{
  "id": 13804623,
  "title": "The Short Test Kept a Dead Cache",
  "url": "https://urgent.news/2026/10/11/the-short-test-kept-a-dead-cache",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-11T21:33:57.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/datacpp_3670/the-short-test-kept-a-dead-cache-4189"
  },
  "original_language": "en",
  "account": "The test case demonstrates a bug where a cached pointer becomes stale after a certain length of input. The issue arises from the `NameTag` struct, which stores a string and a cached pointer to its content. Every time the string is reset or a suffix is added, the cached pointer is updated to point to the new content. However, if the string grows beyond a certain point, the cached pointer becomes invalid, leading to a heap use after free error.\n\nThe key takeaway is that even short unit tests can hide subtle bugs if they don't test for capacity limits. The code provided showcases a simple scenario where a small label type stores one string and one raw pointer. Every reset operation writes both the bytes and the cached pointer, while every suffix mutation mutates the string and leaves the pointer unchanged. The test case shows that even a short name can look harmless during review, but a longer export name can still cause issues after an additional append.\n\nTo fix this issue, it is essential to freeze the failing length and measure the point at which the c_str address starts moving. By logging relevant fields like size, capacities, and pointer equality, developers can identify the exact moment when the stale pointer becomes a problem. Building a sanitizer binary with AddressSanitizer turned on helps catch the bad read and provides valuable insights into the failing function and the exact address involved.",
  "summary": "I will start with the conclusion, not the tool. Caching c_str across growth is a lifetime bug. A short unit test can still pass cleanly. Later growth is what kills the cached pointer. Did your suite ever cross the capacity line? If it did not, the cache only looked stable. A faster coding model does not relax object lifetime. The language rules did not get softer this year. That gap is why this…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}