Review: adium 3497:ab9a06c5cc58: Bonjour bytes
Ryan Govostes
ryan at adium.im
Tue Nov 9 07:00:18 UTC 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://adium.im/pipermail/devel_adium.im/attachments/20101109/1ed0e701/attachment-0002.html>
More information about the devel
mailing list