News for hackers. Stuff that matters.
Re:Tis-interpreter – find subtle bugs in programs written in... by vrfcodf on Saturday April 09, 2016 @02:39AM (#11460237)
That code is well defined.
Re:Tis-interpreter – find subtle bugs in programs written in... by umanwizard on Saturday April 09, 2016 @03:33AM (#11460371)
Doesn't *t = 1 invoke UB if t is null?

Edit: I'm a moron, thanks for pointing out the obvious to me :)

Re:Tis-interpreter – find subtle bugs in programs written in... by PeCaN on Saturday April 09, 2016 @03:35AM (#11460375)
Yes, but note that the assignment occurs after the NULL check. If the grandparent did mean to put it before, then the code snippet would be undefined, but it wouldn't be surprising either.
Re:Tis-interpreter – find subtle bugs in programs written in... by vrfcodf on Saturday April 09, 2016 @03:37AM (#11460381)
I guess one could still be evil and pass a pointer to a non-int type to the function. That example is really bad, you don't need a void pointer to show this ub 'optimization'.
Re:Tis-interpreter – find subtle bugs in programs written in... by PeCaN on Saturday April 09, 2016 @03:42AM (#11460390)
That'd still be defined though. It'd just be defined to set the first sizeof(int) bytes of `* p` to 1. ;) void * and (char * ) can alias to anything and the compiler has to make it work.

Of course if you pass a pointer to a type smaller than sizeof(int)-1 bytes then it accesses uninitialized memory which is UB, but that's a different issue.

EDIT: Aaaand I wasn't thinking.

̶E̶D̶I̶T̶ ̶E̶D̶I̶T̶:̶ ̶N̶o̶t̶ ̶o̶n̶l̶y̶ ̶d̶i̶d̶ ̶I̶ ̶m̶i̶s̶-̶r̶e̶a̶d̶,̶ ̶b̶u̶t̶ ̶v̶o̶i̶d̶ ̶p̶o̶i̶n̶t̶e̶r̶ ̶c̶a̶n̶'̶t̶ ̶a̶l̶i̶a̶s̶ ̶a̶n̶y̶t̶h̶i̶n̶g̶ ̶i̶n̶ ̶s̶t̶a̶n̶d̶a̶r̶d̶ ̶C̶ ̶a̶n̶y̶w̶a̶y̶ ̶(̶t̶h̶o̶u̶g̶h̶ ̶I̶I̶R̶C̶ ̶G̶C̶C̶ ̶t̶r̶e̶a̶t̶s̶ ̶i̶t̶ ̶l̶i̶k̶e̶ ̶c̶h̶a̶r̶ ̶p̶o̶i̶n̶t̶e̶r̶ ̶w̶r̶t̶ ̶a̶l̶i̶a̶s̶i̶n̶g̶)̶.

EDIT EDIT EDIT: Actually maybe it can and I shouldn't be reading technical docs at 2am.

Re:Tis-interpreter – find subtle bugs in programs written in... by vrfcodf on Saturday April 09, 2016 @03:43AM (#11460391)
That is not correct. The type used to write to the memory is int, not void or char. If the object, whose address is passed to the function is not compatible with int, the behavior is undefined.

You should read about strict aliasing, you will be surprised.

Re:Tis-interpreter – find subtle bugs in programs written in... by PeCaN on Saturday April 09, 2016 @03:48AM (#11460400)
You're right, I misread and misinterpreted that! Thanks.

Somehow I wasn't thinking and didn't realize that `t` aliases whatever was passed as `p`, and dereferencing a non int or char pointer would be undefined there.

Re:Tis-interpreter – find subtle bugs in programs written in... by orf on Saturday April 09, 2016 @06:06AM (#11460689)
On Firefox your edit strikethrough makes the page very very wide.
Re:Tis-interpreter – find subtle bugs in programs written in... by quotemstr on Saturday April 09, 2016 @08:10AM (#11460939)
Maybe you should familiarize yourself with the standard before preaching about how easy it is to comply with it.