bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: undefined-behavior obstack.c:139


From: Paul Eggert
Subject: Re: undefined-behavior obstack.c:139
Date: Thu, 14 Dec 2023 16:32:37 -0800
User-agent: Mozilla Thunderbird

On 12/4/23 05:57, Bruno Haible wrote:

In both cases, the ability to add NULL + 0 unifies code paths for
empty arrays and non-empty arrays. Such unified code paths are desirable:
they make the code look simpler.
...
Paul, is the attached patch OK with you?

Thanks, but I'm of two minds about that sort of thing. On the one hand, they document the assumption that (char *) NULL + 0 == NULL. On the other, they are still clutter and this assumption is safe on all but pedantic platforms -- and we've long not worried about pedantic platforms (e.g., gcc -pedantic), for good reason.

Of course, the fact that you found these issues with clang's runtime checking does not mean that these are all the issues; I fully expect that there are others.

All in all, it may be better to leave the code alone.

PS. The name END_OF_ARRAY is not the best, since a null pointer does not point to an array, and even when the pointer is non-null the macro can be used to point elsewhere than to the end of an array. A better name would be something like PTR_ADD, since the first arg is the pointer, the second arg the amount to add.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]