*sigh* gcc <8 UBSan fails to catch this serious, trivial-to-make error:https://godbolt.org/z/kNil_u
-
Show this thread
-
Original test case was slightly wrong and gratuitously distracting. I've now filed a bug report with a much clearer one: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87191 … and it fits in a tweet: void bar(void *); int foo() { char a[10]; bar(&a+2); }
1 reply 1 retweet 1 likeShow this thread -
-
Replying to @cr1901
Yes, legal for any a which is itself legal, but illegal to dereference.
1 reply 0 retweets 0 likes -
Replying to @RichFelker
Oh, I thought only "one past the end of a variable "a" explicitly declared as an array" was a legal pointer. I didn't know it applied to all legal "a".
1 reply 0 retweets 0 likes
6.5.6 Additive operators ¶7: "For the purposes of these operators, a pointer to an object that is not an element of an array behaves the same as a pointer to the first element of an array of length one with the type of the object as its element type."
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.