Re: g_utf8_validate() and NUL characters



Behdad Esfahbod wrote:
> Dan Winship wrote:
>> Maciej Katafiasz wrote:
>>> Den Tue, 07 Oct 2008 16:55:29 -0400 skrev Behdad Esfahbod:
>>>> Ugh.  Why is that?  Who knows?  Matthias suggested that because a string
>>>> claiming to be length bytes long but terminating prematurely is not
>>>> valid. However, that statement assumes that string is nul-terminated.
>>> That is indeed very ugly, and seems to me like a particularly unfortunate 
>>> case of implementation guts spilling out onto the public API and then 
>>> getting documented as invariants :(. Personally I can't think of a single 
>>> reason not to allow NULs if that was the consistent design decision 
>>> across the stack;
>> Sure, but the lower levels of the C stack have already established the
>> rule that a char * is assumed to be NUL-terminated, and methods that
>> take both a char * and a length (strncpy(), strncmp(), strndup(), etc)
>> do so to let you stop before the NUL, not to let you keep going after
>> the NUL.
> 
> Sure, but then there's memcpy, memcmp, memdup, etc for the other behavior.

Lemme repeat again: When dealing with UTF-8 text, a max-length makes zero
sense without inspecting the string first.  So the strncpy, etc behavior is
not relevant.

behdad


> behdad
> 
>> -- Dan
>> _______________________________________________
>> gtk-devel-list mailing list
>> gtk-devel-list gnome org
>> http://mail.gnome.org/mailman/listinfo/gtk-devel-list
>>
> 


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