[commit] Properly cast sentinels for concat()

Mark Kettenis kettenis@jive.nl
Tue Jul 5 07:30:00 GMT 2005


   Date: Tue, 05 Jul 2005 06:34:18 +0200
   From: Eli Zaretskii <eliz@gnu.org>

   > Date: Mon, 4 Jul 2005 18:51:53 -0400
   > From: Daniel Jacobowitz <drow@false.org>
   > Cc: Mark Kettenis <kettenis@jive.nl>, gdb-patches@sourceware.org
   > 
   > You must cast NULL to a pointer type if you use it as the sentinel in a
   > varargs list, in portable code, because 0 is a legal definition of NULL
   > (according to the C standard, which is quite clear on the subject).  On
   > an I32 LP64 system, passing 0 to a varargs function may take 32 bits on
   > the stack while passing NULL takes 64 bits.

   But in Mark's case, NULL is defined as (void *)0, so it's a pointer,
   not an int.

No it isn't, OpenBSD has

#define NULL	0L

which incidentally has the nice property that it makes GCC warn about
a potential problem with the code without actually having that problem
on any OpenBSD platform (which are either ILP32 or LP64).  This
defenition would expose the bug Daniel describes on IL32 P64 platforms
(64-bit Windows, HP-UX on Itanium).

   > Even more C++ implementations use 0, which makes the problem even
   > worse.  ISTR that (void *)0 is not an acceptable definition of NULL in
   > C++.

   We are not talking about C++ code here, nor about a C++ compiler.

Not that I think that it is a good thing, but Andrew has been talking
about making GDB compilable with a C++ compiler before.

Do you still want me to revert the patch?

Mark



More information about the Gdb-patches mailing list