GNOME Bugzilla – Bug 118044
g_log's arg max of 1024 bytes should be chars
Last modified: 2004-12-22 21:47:04 UTC
I had a bug reported against my application which basically meant that information being written to a iochannel was not valid UTF8. I narrowed it down, checking the text at every stage and the buffer was valid UTF8 up until the point I call g_message("%s", buffer) with it. The 'buffer' argument is more than 1024 bytes in this particular case, and when I check the message which has passed through the g_log() functions I notice that it is no more than 1024 bytes. I check the Glib code to find that it has a character array with a maximum size of 1025 bytes and this array is used in the function _g_vsnprintf(), on line 437 here: http://cvs.gnome.org/bonsai/cvsblame.cgi?file=glib%2Fglib/gmessages.c&rev=&root=/cvs/gnome The problem I face is that I am passing an argument which is more than 1025 bytes and is filled with multibyte characters. I suspect the reason I get an "invalid utf8" error is because at the 1024th byte, it is half way through a (in this case Russian) multibyte character, causing incomplete UTF8 characters and hence, invalid UTF8.
Here is a patch which truncates at a character boundary before the buffer end.
Created attachment 18584 [details] [review] patch
Could this be improved to accept unlimited string argument lengths? It was suggested on the gtk-devel-list@gnome.org, that g_strdup_printf() could be utilised. Or has this explicitly NOT been done incase of recursion?
Created attachment 18608 [details] [review] remove string length limitation in the non-recursive case
Committed the g_strdup_printf() patch to HEAD.