#10803: gcc wrongly optimizes NULL check in strdup. ---------------------------------+---------------------------- Reporter: pulkomandy | Owner: axeld Type: bug | Status: new Priority: normal | Milestone: R1 Component: System/libroot.so | Version: R1/Development Resolution: | Keywords: Blocked By: | Blocking: Has a Patch: 0 | Platform: All ---------------------------------+---------------------------- Comment (by bonefish): Replying to [comment:5 pulkomandy]: > I don't see anything in the POSIX spec that explicitly disallows handling NULL pointers. It is undefined, so the implementations are free to gracefully handle a NULL pointer or not. Compliant applications cannot rely on either behavior. In this case there are two implementations, ours and GCC's (and possibly that of other compilers). I think the best solution is to fix the code that relies on NULL being an acceptable argument. Otherwise: * The likely faster intrinsic would have to be disabled. * We'd have to take care that the intrinsic is disabled in all compilers, which is likely to be a trial and error (=crash) process, since the odds are that a future porter of a different compiler won't think of that. * The code wouldn't be portable, which may eventually bite the author. Respectively the author will get used to that specific behavior and erroneously rely on it on other platforms as well. -- Ticket URL: <https://dev.haiku-os.org/ticket/10803#comment:6> Haiku <https://dev.haiku-os.org> Haiku - the operating system.