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

sprintf warning and glib



Here's a piece of the problematic code in glib2:

gint
g_sprintf (gchar       *string,
           gchar const *format,
           ...)
{
  va_list args;
  gint retval;

  va_start (args, format);
  retval = g_vsprintf (string, format, args);
  va_end (args);

  return retval;
}


Now, the issue here is that this code is exactly as evil as having the
sprintf code in the libc. There's also a g_snprintf function right under it,
and as long as client code uses g_snprintf, it will be fine.

What I'd like to be able to do is to compile a glib2 library that will be
as useful as the current libc: that will warn whenever g_sprintf is used,
so that I can identify users of g_snprintf.

Right now, I get lots of extra erroneous warnings for g_sprintf just being
there in the glib2...

Well, we haven't removed sprintf from the libc yet, have we ?

I don't have any simple solution.  What would be ideal would be to be able
to tell the system to just `propagate the warning up' to the g_printf
function, but I see absolutely no way to do that. I know how I could do
this manually (this involves providing a clone of sprintf that wouldn't
warn, sprintf_nowarn, using this locally, and adding the warning to
g_printf) but there is too much possibility for abuse.

Suggestions ?



Visit your host, monkey.org