Re:A bug story: data alignment in C on x86 (2016)
by tedunangst on Tuesday September 04, 2018 @09:55PM
(#17914528)
strlen(null) is pretty straightforward, although being a pure function the compiler might rearrange things.
if (!s) puts("hi");
strlen(s);
I don't think that's guaranteed to print hi if s is null.More fun is memset(0,0,0) which is technically verboten.
In any case, I'd still say strlen(NULL) is qualitatively different than check_ip_header_sum(malloc(4095), 4095). The former's undefined behavior is standard (strlen is expected to dereference the pointer, so it makes sense that it has whatever problems doing that has). The latter shouldn't be expected to exceed the stated bounds without that being clearly stated.