logoalt Hacker News

oguz-ismail2 • today at 9:54 AM • 1 reply • view on HN

Right. If fmt was "%d%d" and val had only one element that'd cause an out-of-bounds read as well. Can't say it's a bug without seeing the rest of the code though; if the function is used correctly everywhere, there's no bug.


Replies

tgv • today at 11:29 AM

> there's no bug

That's a bit of an ontological conundrum: does a bug exist when it never occurs? I'd say there is a bug, unless the function has a contract that guarantees there's always a character following every first % (and something about the length of the second array, of course). So I see a bug as something wrong with the design.

But if you see a bug as something purely pertaining to runtime, then you are right. But when is "never"? If it is proven not to occur, or is it enough that the circumstances in which it is used just happen no to trigger it? (Note that in the last phrase, "it" refers to the bug, and implies it exists...)

BTW, in the example, the partial evaluator could prove the presence or absence of bugs.