Time: 0:00
Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).
This bug belongs to the type errors pattern
Totals that concatenate, sorts that put 10 before 9, comparisons that refuse to run.
What went wrong: std::string::npos is defined as static const size_t npos = -1 (which is 18446744073709551615 on 64-bit systems). Storing it into a 32-bit signed int overflows and comparing pos >= 0 can evaluate to true or cause implementation-defined behavior.
The fix: Compare pos directly against std::string::npos before casting to an int.
Remember: Always compare the return value of std::string::find directly with std::string::npos.
The pattern behind it: type errors.
Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.
<iframe src="https://trybughunt.com/embed/5ba7cae5-8270-415e-8acf-685f5a329695" title="Debugging challenge: std::string::find comparison with signed integer" 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/5ba7cae5-8270-415e-8acf-685f5a329695">TryBugHunt</a></p>