11 ms·
How does this happen? My guess is there is a loop that processes file contents in 8KB blocks, something like this: bytesRemaining = fileSize; while(...
by userbinator 12y ago
How does this happen? My guess is there is a loop that processes file contents in 8KB blocks, something like this:
bytesRemaining = fileSize;
while(...) {
...
bytesRemaining -= 8192;
if(bytesRemaining < 0)
break;
...
}
bytesRemaining += 8192;
...
// process remaining bytes
See the bug? :-)
- meowface 12y agoVery likely something like this or similar to this.
- Diamons 12y agoThe power of the almighty equal sign
- derekchiang 12y agoIf this was the case then any multiple of 8KB should also cause the bug to happen, but according to OP only exactly 8KB causes the bug.
- jerryr 12y agoYes. The while statement can't take variable arguments. Also, ellipsis is not a standalone expression. Also, if "fileSize" is exactly 8192 then ellipsis will execute because "bytesRemaining" will equal zero. If your compiler actually compiles ellipsis and "fileSize" is exactly 8192, then something bad will probably happen. Either the undefined behavior of the compiled ellipses or the unexpected negative number will likely cause a crash. Edit: I guess that was funnier in my head.
- deleted 12y ago[deleted]