Steve Fink wrote:

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,

no, a string extends from strstart to strstart+bufused bytes. The buflen is always the total buffer size.

So s/strlen/bufused/ is ok for above snippet.

leo

Reply via email to