Re: How do online html docs in GTK+? in /portable/ way possible too?



On Tue, 25 Jun 2002 16:22:33 BST, Chris Wareham said:

> Zarro boogs here. A char is one byte - and it has little relevance when
> talking about "representable glyphs". A char doesn't necessarily imply

Right.  Not *necessarily*.

> that one is dealing with strings of printable characters, it is simply a

>>                     tokptr = strtok(NULL, " ");

*THIS* code is pretty obviously thinking in terms of strings of printables.

> shorthand for an integral type. My operating system happens to use the
> ASCII character set, so it also happens to map nicely onto a char. Now
> if my operating system used Unicode throughout then that would be a
> whole different kettle of fish ...

Ahh.. but gtk uses something *other than ASCII*.

And thus  assuming that sizeof(char) * (len+1) will result in enough storage

>>                 ptr = g_malloc(sizeof(char) * (len + 1));

is a bug.  The code as written will just "happen to work" for ASCII and
other codesets where the UTF-8 encoding happens to not require extra bytes
(I'd have to check if all 8859-X charsets have this property - probably not,
as the UTF-8 encoding will require at least a few bits to say which -X it is.

And if the UTF-8 encoding is longer, you won't g_malloc enough.  And THAT
is where the bug is.
-- 
				Valdis Kletnieks
				Computer Systems Senior Engineer
				Virginia Tech

Attachment: pgpojjtJt0oAK.pgp
Description: PGP signature



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