On Jan-11, Leopold Toetsch wrote:
> Brent Dax wrote:
> 
> >Steve Fink:
> >#   -    memcpy(targ, ret->strstart, ret->bufused);
> >#   -    targ[ret->bufused + 1] = '\0';
> >#   +    memcpy(targ, ret->strstart, ret->strlen);
> >#   +    targ[ret->strlen] = '\0';
> >
> >I could be wrong, but isn't strlen the length in characters rather than
> >the length in bytes?
> 
> Yep. But as the string is trans_coded to the default encoding, it 
> doesn't matter. The default encoding is singlebyte.

Ick. That's a kind of complicated proof of correctness. (Especially
since I didn't even think about the char/byte issue -- I should add a
comment, at least.)

Is there a better way to do this? The original was clearly off by one,
and was leaving an extra junk character in the buffer (that's how I
ran into this -- "0x0" was turning into "0x0\b", and printing out as
"0x"). But I also thought that if strstart != bufstart, then bufused
referred to the length of the buffer, not the length of the portion of
the buffer used by the string. From looking through string.c, it
appears that the original was correct in using bufused instead of
strlen. Could someone confirm that before I revert that part of the
patch? (Sorry, I'm sure this is documented somewhere, but I'm lazy.)

Reply via email to