Richard Frith-Macdonald wrote:

> We could probably adapt your patch to use precision as string lengh in those 
> cases where it will work, but you can't catch all cases that way ... so maybe 
> it's better if people find out as soon as possible that c-strings have to be 
> nul terminated.
> 
> Sorry about this ... but it's a behavior inherited from the C stdio library 
> and posix etc standards.  My own feeling is that format strings *ought* to 
> provide some way of working with unterminated strings, but they just don't, 
> so you have to copy the data into a big enough buffer, add the nul 
> terminator, and use that buffer intead of the original data :-(

I don't think your description of the standards is correct. My copy of the ANSI 
C'99 standard has this to say on the %s format specifier:
"If the precision is specified, no more than that many characters are written. 
If the precision is not specified or is greater than the size of the array, the 
array shall contain a null character.
With that specification, I'd say that Chris's code is correct. He uses an array 
containing 50 bytes and uses precision 50, so the array shouldn't require a 
NULL terminator.

Wolfgang


_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to