Be more robust against printf failures

If an 'output error' is encountered, vsnprintf() will return -1,
causing g_printf_string_upper_bound() to return 0. Handle this
case in g_vasprintf() without crashing.

Fixes: #3187
This commit is contained in:
Matthias Clasen 2023-11-26 21:52:36 -05:00
parent 40081f9b62
commit bd6a22c4ab

View File

@ -358,19 +358,23 @@ g_vasprintf (gchar **string,
#else
{
va_list args2;
va_copy (args2, args);
*string = g_new (gchar, g_printf_string_upper_bound (format, args));
len = _g_vsprintf (*string, format, args2);
va_end (args2);
if (len < 0)
if (*string == NULL)
len = -1;
else
{
g_free (*string);
*string = NULL;
va_list args2;
va_copy (args2, args);
len = _g_vsprintf (*string, format, args2);
va_end (args2);
if (len < 0)
{
g_free (*string);
*string = NULL;
}
}
}
#endif