101010.pl is one of the many independent Mastodon servers you can use to participate in the fediverse.
101010.pl czyli najstarszy polski serwer Mastodon. Posiadamy wpisy do 2048 znaków.

Server stats:

484
active users

наб

hey @thephd does Very Old ISO C have Rationales or "History of Decision Made"s (I would like to know if the reason C allows malloc(0)=0 is because it believes the SVID which says this happens on SysV (it doesn't, the manual lies. malloc(0)≠0 always (unless OOM), and this has always been the case in every malloc implementation ever (on anything unix-shaped)))

okay it's just because SVID says this probably

@nabijaczleweli @thephd OSF/1 AD on i860 returned 0 for malloc(0) and we hated it enough to patch the system library on our paragon.

@nabijaczleweli hats off, amazing research.

Although…

every default malloc(0) ever behaved

… the absolute word “every” there bogs me a bit. Every one in released Unicēs, sure.

But what about hobbyist unixoid systems like Minix, Linux, or unix-ish layers like Cygwin, UWIN, PW32, etc. (Midipix TTBOMK uses musl), or even other C-using systems with malloc?

If it’s been in some standard for long enough, someone’s bound to have fucked it up…

@mirabilos predicated on "within the area this document surveys," :)

(also the overwhelming precedent in all common implementations (glibc/musl/illumos/{Free,Net,Open}BSD/msys2) is malloc(0) != 0, too (but realloc(..., 0) is "much worse", cf. rCs's open-std.org/jtc1/sc22/wg14/ww). linux libc5/minix{1,2} i haven't interrogated, but they're all reimplementations-from-some-standard and, thus, not really interesting to me. my bet is that you'll find /some/ C implementations with malloc(0)=0, with more unixy => less likely? but that's law of large numbers)

@nabijaczleweli true that.

That paper tho…

  • saying BSD but not which and I know for sure they have vastly different mallocs, otto@ even wrote one from scratch for OpenBSD
  • indicating POSIX can only define the behaviour if C leaves it undefined, whereas IB would suffice

@mirabilos @nabijaczleweli Making IT UB acknowledges that programs relying on implementation-defined behavior would be dangerous on other platforms.

@uecker @nabijaczleweli on all platforms

GCC has no -std=posix, it will happily break programs that make assumptions POSIX guarantees that C says are UB at least

@mirabilos @nabijaczleweli Well, you will get POSIX semantics guaranteed only on implementations that are POSIX compliant. Or you write against ISO C23 and then you know that realloc with zero is unreliable (on the wider range of implementations targeted by ISO C)

@uecker @nabijaczleweli if so, POSIX’ guarantees are meaningless and can be removed entirely. POSIX-compliant OSes are… what, two commercial Unicēs and that’s it, or something?

I’m far more interested in systems people can and do actually use, which overwhelmingly use GCC (and Clang+LLVM, though I think it also has no -std=posix either).

Additionally, C’s UB is not something implementations can just override. If they could, it would have been labelled IB.

@mirabilos @nabijaczleweli Then just do not rely on realloc with zero...

I am not sure what you mean by "implementations can not override UB". The use as extension point is one of the main use cases of UB. We prefer to make things IB nowadays, but it had a more restricted definition in the past.

@uecker @nabijaczleweli in my own software I don’t, but I’d prefer being able to compile software that historically worked without getting extra trouble…

@mirabilos @nabijaczleweli I don't see why historical software would now break - assuming it worked before (which it already didn't when it relied on specified realloc behavior and was used on the wrong platform)

@nabijaczleweli small typo in your doc - the SunOS 3.4 section is titled "4.1.3".

Also, I can't swear to the accuracy, but the Imake configs for building the X Window System included static information about which platforms they thought might return NULL from malloc(0), including SysV platforms that might link with -lmalloc, and there were a fair number listed:
gitlab.freedesktop.org/search?

GitLabMalloc0ReturnsNull · Search · GitLab38 blobs for term 'Malloc0ReturnsNull'