[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString bug with test and really dodgy patch.

From: Wolfgang Lux
Subject: Re: NSString bug with test and really dodgy patch.
Date: Wed, 3 Oct 2012 09:09:56 +0200

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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]