GNOME Bugzilla – Bug 361428
segmentation fault on win32 - g_vsnprintf if argument for %s is NULL
Last modified: 2006-10-11 14:55:37 UTC
Steps to reproduce: 1. g_vsnprintf(buffer, 512, "%s", NULL); 2. 3. Stack trace: Other information:
verify line 546 on file glib-2.12.1/glib/gnulib/vasnprintf.c: tmp_length = strlen (a.arg[dp->arg_index].a.a_string); error on strlen if "a.arg[dp->arg_index].a.a_string" is NULL.
Not a bug. NULL is not a legal argument for %s. That some C libraries "helpfully" accept NULL anyway and print "(null)" or something similar is irrelevant.
Ok, you're right, but take it as a suggestion :) Several linux codes use it without problem (glibc prints "(null)" helpfully). But, when they are compiled for win32, they have problems. I think that implementation would improve the cross-platform characteristcs of glib. Thankx.
But even if we fix the g_*print* functios, the behaviour of plain *printf functions directly from the (Microsoft) C library wouldn't change, which could be confusing. Oh well, I guess whether something should be done to thins issue depends on how we specify the g_*print* functions to behave. Now the documentation doesn't promise anything special. g_printf documentation just says "An implementation of the standard printf() function which supports positional parameters, as specified in the Single Unix Specification." Remember that there are other platforms that Win32 and Linux; many proprietary UNIXes presumably have C libraries where printf crashes if you feed a NULL to %s. Not to mention embedded platforms.
I agree. From now on, I'll code taking care of it. Thanks.