On Nov 9, 2010, at 1:18 AM, Peter Hosey wrote:
> http://hg.adium.im/adium/rev/ab9a06c5cc58
>
>> Patch from an anonymous source to use bytes instead of an NSString for this
>> raw data, thereby silencing a Clang warning about null bytes in an NSString.
>> The bytes are simply tacked onto an NSMutableData.
>
> ...
>
> The output is now wrong.
>
> Remember that C strings are null-terminated, and a C array (e.g., const char
> []) initialized with one will include the null terminator. Therefore, the
> C-array subn contains one more byte than the NSString subn contained
> characters. The same is true of endn.
>
> There are two possible fixes:
>
> 1. Use strlen instead of sizeof.
No, this would not work since there are null bytes.
> 2. Declare an enum symbol for the desired number of characters, and use each
> symbol both to declare the length of the corresponding array and to replace
> the sizeof expressions.
Would this suffice?
> const char subn[] = "subn\x00\x00\x00\x01";
-->
> const char subn[] = { 's', 'u', 'b', 'n', '\x00', '\x00', '\x00', '\x01'};
Regards,
Ryan Govostes