bug in g_[v]snprintf() ?



Looking at g_vsnprintf() and g_snprintf() in Glib 1.2.4, I noticed that
neither checks to see if the buffer pointer is NULL.  I'm not sure what
will happen if the system used has vsnprintf(), but if it doesn't then
won't the strncpy() in either Glib function cause segfaults?

I think the best fix for this would be to add the following line to both
functions right before the test for HAVE_VSNPRINTF:

   g_return_val_if_failed ( str != NULL, -1 );

This way the caller can check to see if the call truly failed (unlike some
of the other string functions in Glib).  However, this probably wouldn't
work on vsnprintf()-supported systems.  So maybe 

   g_return_val_if_failed ( str != NULL, 0 );

would be best (it at least would be consistant with other Glib string 
functions).

I'd think this would be an argument for adding a g_errno global value to glib,
but I could be wrong.
-- 
Michael J. Hammel           |    All the worlds a stage, and all the men and
The Graphics Muse           |    women merely players.
mjhammel@graphics-muse.org  |            Shakespeare, "As You Like It", II, 7
http://www.graphics-muse.org 



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