[Bug c/87191] UBSan doesn't catch invalid pointer arithmetic outside known object bounds

bugdal at aerifal dot cx gcc-bugzilla@gcc.gnu.org
Mon Sep 3 03:14:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87191

--- Comment #2 from Rich Felker <bugdal at aerifal dot cx> ---
This PR is about UBSan. I agree it's usually preferable to detect this type of
error statically by warnings, and I also filed #87192 for -Warray-bounds not
being able to catch the specific type of case I was affected by.

However, UB of this form is a dynamic condition at runtime, and any static
tests will have either false negatives or false positives, e.g. when the code
is reachable only conditionally on the size of the array and the conditional is
not locally visible.

In my case I tried UBSan as a fallback since I was surprised that no warning
was being generated, and when I found the UBSan also failed to catch the
problem, I reported this bug.


More information about the Gcc-bugs mailing list