[glib: 1/2] glib-compile-resources: Fix generated code compiling with C++ compilers
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] glib-compile-resources: Fix generated code compiling with C++ compilers
- Date: Fri, 31 Aug 2018 12:50:51 +0000 (UTC)
commit b1cae79f78c5e6dc2f029993a4e936be7fe55af4
Author: Philip Withnall <withnall endlessm com>
Date: Fri Aug 31 12:29:39 2018 +0100
glib-compile-resources: Fix generated code compiling with C++ compilers
With 0d685b494637775edcb6941706fb047217c48b3f, 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>
gio/glib-compile-resources.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/gio/glib-compile-resources.c b/gio/glib-compile-resources.c
index 765cf83ed..6ce5aec4a 100644
--- a/gio/glib-compile-resources.c
+++ b/gio/glib-compile-resources.c
@@ -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"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]