From 793f801a5ccc76645e569adb971eeced67e763be Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 18 Feb 2014 17:41:29 +0100 Subject: removed unreliable CHR2STR() macro * referencing temporaries is unreliable/buggy in GNU C++, at least since v4.7 * in higher optimization levels it resulted in massive memory corruptions * this is responsible for the build issues (PPA build issues) * instead, always declare a buffer on the stack which guarantees that the variable lives long enough * the g_strdup(CHR2STR(x)) idiom has been replaced with String::chrdup(x) --- src/sciteco.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/sciteco.h') diff --git a/src/sciteco.h b/src/sciteco.h index 65b8e9a..1a349a1 100644 --- a/src/sciteco.h +++ b/src/sciteco.h @@ -63,15 +63,22 @@ extern sig_atomic_t sigint_occurred; #define IS_SUCCESS(X) ((X) < 0) #define IS_FAILURE(X) (!IS_SUCCESS(X)) -/* - * NOTE: compound literals are temporaries beginning with - * g++ 4.7 - */ -#define CHR2STR(X, ...) \ - ({gchar str[] = {(X), ##__VA_ARGS__, '\0'}; str;}) - namespace String { +static inline gchar * +chrdup(gchar chr) +{ + gchar *ret = (gchar *)g_malloc(2); + + /* + * NOTE: even the glib allocs are configured to throw exceptions, + * so there is no error handling necessary + */ + ret[0] = chr; + ret[1] = '\0'; + return ret; +} + static inline void append(gchar *&str1, const gchar *str2) { @@ -84,7 +91,8 @@ append(gchar *&str1, const gchar *str2) static inline void append(gchar *&str, gchar chr) { - append(str, CHR2STR(chr)); + gchar buf[] = {chr, '\0'}; + append(str, buf); } /* in main.cpp */ -- cgit v1.2.3