This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

Re: Fix for off-by-one error in cpplib


>>>>> 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

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