Fix for off-by-one error in cpplib

Andreas Jaeger aj@suse.de
Mon Mar 13 09:08:00 GMT 2000


>>>>> grahams  writes:

Graham> Andreas, Zack, ...
Graham> Andreas Jaeger wrote:
[..]
Graham> Whoops we are now putting the '\0' in the wrong place
Graham> (i.e past the end of the allocated buffer)

Oh no, not again a broken patch by me for this wee problem :-(.
You're right.

Graham> I think the following does the correct thing!

>> name = pfile->token_buffer + written + 1;
>> len = strlen (name);
>> -  copy = (U_CHAR *) alloca (len);
>> +  copy = (U_CHAR *) alloca (len + 1)
>> -  memcpy (copy, name, len - 1);
>> +  memcpy (copy, name, len);

>> copy[len] = '\0';    /* trim trailing quote */

Looks ok to me.

Thanks a lot,
Andreas
-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.rhein-neckar.de


More information about the Gcc-patches mailing list