The non `USE_XLOCALE` implementation of `g_ascii_formatd` is broken for format strings that don't start with `'%'`
I detected this while running pango's testsuite on musl libc. Given that musl doesn't implement strtoll_l
or strtoull_l
, glib is using the non USE_XLOCALE
fallback code.
pango/pango-attributes.c
calls g_ascii_formatd (buf, 20, " %f", flt->value);
. This works with USE_XLOCALE
, since things are directly passed to _g_snprintf
. Without it, however, we trigger many assertions:
const char *decimal_point;
gsize decimal_point_len;
gchar *p;
int rest_len;
gchar format_char;
g_return_val_if_fail (buffer != NULL, NULL);
g_return_val_if_fail (format[0] == '%', NULL);
g_return_val_if_fail (strpbrk (format + 1, "'l%") == NULL, NULL);
format_char = format[strlen (format) - 1];
g_return_val_if_fail (format_char == 'e' || format_char == 'E' ||
format_char == 'f' || format_char == 'F' ||
format_char == 'g' || format_char == 'G',
NULL);
if (format[0] != '%')
return NULL;
if (strpbrk (format + 1, "'l%"))
return NULL;
if (!(format_char == 'e' || format_char == 'E' ||
format_char == 'f' || format_char == 'F' ||
format_char == 'g' || format_char == 'G'))
return NULL;
The code seems to assume that format strings are exclusively of the format "%f"
or "%1.1f"
, which is not documented anywhere. This seems to be the case since the function's introduction, in 3c39c8fc.
I think removing the dependency on strtoull_l
and strtoll_l
for most of the USE_XLOCALE
code is reasonable (and can send a patch to this effect), but fixing the fallback code is still important.