From b1cae79f78c5e6dc2f029993a4e936be7fe55af4 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 31 Aug 2018 12:29:39 +0100 Subject: [PATCH] glib-compile-resources: Fix generated code compiling with C++ compilers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- 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"