![]() |
|
Message-ID: <20250619123613.GC2742@qaa.vinc17.org> Date: Thu, 19 Jun 2025 14:36:13 +0200 From: Vincent Lefevre <vincent@...c17.net> To: Alejandro Colomar <alx@...nel.org> Cc: Rich Felker <dalias@...c.org>, linux-man@...r.kernel.org, musl@...ts.openwall.com, libc-alpha@...rceware.org, Paul Eggert <eggert@...ucla.edu>, Bruno Haible <bruno@...sp.org>, bug-gnulib@....org Subject: Re: malloc.3: Clarify realloc(3) standards conformance On 2025-06-19 12:54:52 +0200, Alejandro Colomar wrote: > +BUGS > + Programmers would naturally expect that realloc(p, n) is consis‐ > + tent with free(p) and malloc(n). This is not explicitly re‐ > + quired by POSIX.1‐2024, but all conforming implementations are > + consistent with that. > + > + The glibc implementation of realloc() is not consistent with > + that, and as a consequence, it is dangerous to call > + realloc(p, 0) in glibc. > + > + A trivial workaround for glibc is calling it as > + realloc(p, n?:1). n?:1 is a GNU extension: warning: ISO C forbids omitting the middle term of a ‘?:’ expression [-Wpedantic] with gcc -pedantic -std=c23, and such code should not be given in examples (as a workaround should still be valid for portable code). -- Vincent Lefèvre <vincent@...c17.net> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.