This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Don't call strchr with the NULL character.
- From: <Paul_Koning at Dell dot com>
- To: <aburgess at broadcom dot com>
- Cc: <gdb-patches at sourceware dot org>
- Date: Thu, 11 Jul 2013 16:48:05 +0000
- Subject: Re: [PATCH] Don't call strchr with the NULL character.
- References: <51DEDA0E dot 8020809 at broadcom dot com>
On Jul 11, 2013, at 12:15 PM, Andrew Burgess wrote:
> In the printf code we call strchr without guarding against the
> case where the second parameter is NULL.
>
> My local manpage for strchr doesn't say what happens in this case,
> but this file: src/libiberty/strchr.c
> suggests the results are undefined, and indeed, the answer I see is
> not NULL (which is what I might have hoped for).
The BSD manpage (for example on Mac OS) says:
The strchr() function locates the first occurrence of c (converted to a
char) in the string pointed to by s. The terminating null character is
considered to be part of the string; therefore if c is `\0', the func-
tions locate the terminating `\0'.
It looks like libiberty/strchr.c does the same thing. It doesn't look undefined at all.
paul