This is the mail archive of the gdb-patches@sources.redhat.com 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: Minor off-by-one error in command_line_handler


Andreas Schwab writes:
 > Elena Zannoni <ezannoni@redhat.com> writes:
 > 
 > |> Andrew Cagney writes:
 > |>  > > 2002-03-26  Jason Molenda  (jason-cl@molenda.com)
 > |>  > > 
 > |>  > > 	* event-top.c (command_line_handler): Don't check penultimate
 > |>  > > 	byte in zero-length strings.
 > |>  > > 
 > |>  > > 
 > |>  > Yes, and thanks.
 > |>  > 
 > |>  > Andrew
 > |>  > 
 > |>  > 
 > |> 
 > |> Wait.  This is fine, but, as the comments indicate, the code was taken
 > |> from the function command_line_input in top.c, which has the same bug:
 > |> 
 > |>       p1 = rl;
 > |>       /* Copy line.  Don't copy null at end.  (Leaves line alone
 > |>          if this was just a newline)  */
 > |>       while (*p1)
 > |> 	*p++ = *p1++;
 > |> 
 > |>       xfree (rl);		/* Allocated in readline.  */
 > |> 
 > |>       if (p == linebuffer || *(p - 1) != '\\')
 > |> 	break;
 > 
 > Why?  This one looks ok.

Oh, You mean because the second part of the 'or' won't be evaluated if 
p==linebuffer (which implies that the line was empty)?

Wonder if this gives an error if run under valgrind (use the --noasync
switch). 

Looking at the logs, the error in event-top.c came in because that
first part of the OR was deleted.

 > 
 > Btw., command_line_handler has this:
 > 
 > 
 >   if (*(p - 1) == '\\')
 >     {
 >       p--;			/* Put on top of '\'.  */
 > 
 >       if (*p == '\\')
 > 
 > The condition in the last line is always true.
 > 

Yes, thanks for catching this. Would you like to submit a fix?

Elena


 > Andreas.
 > 
 > -- 
 > Andreas Schwab, SuSE Labs, schwab@suse.de
 > SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
 > Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
 > "And now for something completely different."


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