top | item 43775089

(no title)

burch45 | 10 months ago

Undefined behavior to access the uninitialized memory. A sanitizer would have flagged that.

discuss

order

jandrese|10 months ago

The compiler has no way of knowing that the memory would be undefined, not unless it somehow can verify the data file. The most I think it can do is flag the program for not checking the return value of scanf, but even that is unlikely to be true since the program probably was checking for end of file which is also in the return value. It was failing to check the number of matched parameters. This is the kind of error that is easy to miss given the semantics of scanf.

nayuki|10 months ago

> The compiler has no way of knowing that the memory would be undefined

Yes it would. -fsanitize=address does a bunch of instrumentation - it allocates shadow memory to keep track of what main memory is defined, and it checks every read and write address against the shadow memory. It is a combination of compile-time instrumentation and run-time checking. And yes, it is expensive, so it should be used for debugging and not the final release.

https://clang.llvm.org/docs/AddressSanitizer.html , https://learn.microsoft.com/en-us/cpp/sanitizers/asan?view=m...

andrewmcwatters|10 months ago

Uninitialized variables are a really common case.

andrewmcwatters|10 months ago

Yeah, the debugging here is great, but the actual cause is super mild.