NSByteCountFormatter corrupts negative counts
| Originator: | me | ||
| Number: | rdar://13268309 | Date Originated: | 21-Feb-2013 03:42 PM |
| Status: | Open | Resolved: | |
| Product: | Mac OS X | Product Version: | 10.8.2 (12C3006) |
| Classification: | Serious Bug | Reproducible: | Always |
NSByteCountFormatter's -stringFromByteCount: and +stringFromByteCount:countStyle: methods take a (signed) long long for 'byteCount'. However, passing a negative value instead returns a string for a very large positive number. (Likely the value is being unsafely cast to an unsigned number internally.) +[NSByteCountFormatter stringFromByteCount:1024 countStyle:NSByteCountFormatterCountStyleMemory] => '1 KB' +[NSByteCountFormatter stringFromByteCount:-1024 countStyle:NSByteCountFormatterCountStyleMemory] => '16 EB' Expected value: '-1 KB'. Or, change the type of the 'byteCount' parameter to unsigned, so the compiler can warn callers if they pass a possibly-negative value.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!