Time: 0:00
Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).
This bug belongs to the scope and closure bugs pattern
Every callback reports the last value, a counter never increments, UnboundLocalError on a variable you can see.
What went wrong: The std::string_view outlived the temporary std::string it referenced, leading to undefined behavior when accessing the memory.
The fix: Change the function parameter from std::string_view to const std::string& to ensure the string lives long enough.
Remember: Always ensure that std::string_view does not outlive the string it references to avoid undefined behavior.
The pattern behind it: scope and closure bugs.
Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.
<iframe src="https://trybughunt.com/embed/9e7c3c9c-ffb0-472c-b2ee-f1ba58654e47" title="Debugging challenge: Unexpected crash when processing string view in function" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/9e7c3c9c-ffb0-472c-b2ee-f1ba58654e47">TryBugHunt</a></p>