Re: undefined-behavior obstack.c:139

"Andreas F. Borchert" <[email protected]> Sat, 2 Dec 2023 18:16:02 +0100
Newsgroups gmane.comp.gnu.m4.bugs,gmane.comp.lib.gnulib.bugs
Message-ID <[email protected]>
On Sat, Dec 02, 2023 at 09:50:33AM +0100, Bruno Haible wrote:
> I still don't know whether it's OK to have pointers to arrays with
> 0 elements (which are not "array objects", since "objects" are non-
> empty (§ 6.2.6.1.(2))).

From § 6.7.6.2 about array declarators:

   If the expression is a constant expression, it shall have a
   value greater than zero.

Hence, arrays must have at least one element. And in case of
memory management functions, the behaviour is implementation-defined
for a requested size of zero (see § 7.24.3) and null
pointers are possible. Hence pointer arithmetic is not supported
for pointers returned by malloc(0).

Andreas

-- 
Dr. Andreas F. Borchert,  Institut für Numerische Mathematik, Universität Ulm
Helmholtzstr. 20, 89081 Ulm, +49 7315023572 https://mathematik.uni-ulm.de/afb
smime.p7s (application/x-pkcs7-signature, 5.9 KB) - not displayed