mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-23 20:46:14 +01:00
gstring: Add critical warning to g_string_append_vprintf()
It was previously possible for this to silently fail, which isn’t great for program correctness. Instead, raise a critical warning so the programmer knows to either validate their Unicode inputs, or fix their format placeholders. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #3187
This commit is contained in:
parent
c56bc6d8d9
commit
707ae4bd79
@ -1221,6 +1221,10 @@ g_string_append_vprintf (GString *string,
|
||||
string->len += len;
|
||||
g_free (buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_critical ("Failed to append to string: invalid format/args passed to g_vasprintf()");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -319,11 +319,17 @@ test_string_append_vprintf (void)
|
||||
|
||||
string_append_vprintf_va (string, "some %s placeholders", "format");
|
||||
|
||||
if (g_test_undefined ())
|
||||
{
|
||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
||||
"Failed to append to string*");
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#pragma GCC diagnostic ignored "-Wformat-extra-args"
|
||||
string_append_vprintf_va (string, "%l", "invalid");
|
||||
#pragma GCC diagnostic pop
|
||||
g_test_assert_expected_messages ();
|
||||
}
|
||||
|
||||
g_assert_cmpstr (string->str, ==, "firsthalfsome format placeholders");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user