mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
glib-compile-resources: Fix generated code compiling with C++ compilers
With 0d685b4946
, we now encode resource
data as a string. Strings have trailing nul terminators. A C compiler
will happily ignore the fact that the nul terminator exceeds the stated
array length, and will drop it — but a C++ compiler won’t, and will
raise:
error: initializer-string for array of chars is too long [-fpermissive]
Fix that by increasing the array length by 1, and subtracting it again
in the GStaticResource struct.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
ea17d637c5
commit
b1cae79f78
@ -1088,7 +1088,7 @@ main (int argc, char **argv)
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"static const SECTION union { const guint8 data[%"G_GSIZE_FORMAT"]; const double alignment; void * const ptr;} %s_resource_data = {\n \"",
|
||||
c_name_no_underscores, data_size, c_name);
|
||||
c_name_no_underscores, data_size + 1 /* nul terminator */, c_name);
|
||||
|
||||
for (i = 0; i < data_size; i++) {
|
||||
g_fprintf (file, "\\%3.3o", (int)data[i]);
|
||||
@ -1100,7 +1100,7 @@ main (int argc, char **argv)
|
||||
|
||||
g_fprintf (file,
|
||||
"\n"
|
||||
"static GStaticResource static_resource = { %s_resource_data.data, sizeof (%s_resource_data.data), NULL, NULL, NULL };\n"
|
||||
"static GStaticResource static_resource = { %s_resource_data.data, sizeof (%s_resource_data.data) - 1 /* nul terminator */, NULL, NULL, NULL };\n"
|
||||
"%s GResource *%s_get_resource (void);\n"
|
||||
"GResource *%s_get_resource (void)\n"
|
||||
"{\n"
|
||||
|
Loading…
Reference in New Issue
Block a user