This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Don't call strchr with the NULL character.


On 11/07/2013 5: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).

Thanks to both Andreas and Paul for pointing out more up to
date manual pages that explain the behaviour is NOT undefined
at all.

That said, my patch (I believe) fixes gdb given the /current/
behaviour, which I thought was undefined, but is in fact well
defined.  Either way I believe this patch is required.

Here's an example from before my patch:

	while (strchr ("0-+ #", *f))
	  {
	    if (*f == '#')
	      seen_hash = 1;
	    else if (*f == '0')
	      seen_zero = 1;
	    else if (*f == ' ')
	      seen_space = 1;
	    else if (*f == '+')
	      seen_plus = 1;
	    f++;
	  }

If *f is the end of string NULL character then the loop
above will run off the end of the string.


Thanks,
Andrew


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]