Bug in NSString stringWithFormat (or sprintf)?
Bug in NSString stringWithFormat (or sprintf)?
- Subject: Bug in NSString stringWithFormat (or sprintf)?
- From: Christian Mike <email@hidden>
- Date: Mon, 20 Aug 2001 16:21:47 -0500
I may have found a bug in NSString stringWithFormat. This may or may not be
a bug and it may or may not be known.
If I create a string:
NSString *stringTemp = [NSString
stringWithFormat:@"%.4s","abcdefgh"];
stringTemp will now contain the string "abcdefgh". I was expecting just
"abcd".
In any other C compiler that I have worked with, if you specify a precision
for a character string in a format specifier, this precision says output AT
MOST "n" characters, but stop if you encounter a NULL byte. For this example
(and I got the same results with sprintf), the precision digit appears to be
ignored on the string specifier, and the transfer continues until a NULL
byte is encountered.
Is this a bug?
Michael Christian
Thomson multimedia Inc.