A highly invalid "optimization" by clang. That compiler needs -fno-builtin to be usable.
-
-
-
Because it violates the as-if rule. The calloc call is required to fail; transformation makes it succeed.
1 reply 0 retweets 1 like -
Replying to @RichFelker @solardiz
What requires this calloc call to fail? C11? POSIX? For all sizes > PTRDIFF_MAX? Or > SIZE_MAX?
2 replies 0 retweets 0 likes -
Multiple things. The most important is the compiler's inability to handle objects > PTRDIFF_MAX in a consistent manner.
2 replies 0 retweets 0 likes -
Replying to @RichFelker @solardiz
I consider this a bug in compilers. Which would be nice to fix. This is not a requirement of some standard.
2 replies 0 retweets 0 likes -
Supporting objects >PTRDIFF_MAX rather than ensuring they don't exist is a QoI bug even if not a conformance issue.
1 reply 0 retweets 0 likes -
The - operator is not safe to use on pointers unless the implementation precludes objects > PTRDIFF_MAX.
2 replies 0 retweets 0 likes -
Replying to @RichFelker @solardiz
The - operator is only not safe in C for arrays of chars larger than PTRDIFF_MAX.
2 replies 0 retweets 0 likes -
The + operator is much more dangerous -- you can easily get OOB pointer. Why so much attention to -?
1 reply 0 retweets 1 like
The + operator is only used when the integer operand is known to be a valid offset for the pointer operand; it's safe.
-
-
Replying to @RichFelker @solardiz
Not necessarily. Even if we limit ourselves to only natural cases there would be problems. E.g. end pointers.
1 reply 0 retweets 0 likes -
It is kinda natural to write p < s + n in an implementation of memchr but it's wrong.
0 replies 0 retweets 0 likes
End of conversation
New conversation -
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.