aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sciteco.h
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2014-02-18 17:41:29 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-02-18 17:41:29 +0100
commit793f801a5ccc76645e569adb971eeced67e763be (patch)
tree3c095a73a0d16b890fe0e8fe6dfce86190501410 /src/sciteco.h
parent0674f295767f2e953baf2eec13cdd4be52468ca1 (diff)
downloadsciteco-793f801a5ccc76645e569adb971eeced67e763be.tar.gz
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)
Diffstat (limited to 'src/sciteco.h')
-rw-r--r--src/sciteco.h24
1 files changed, 16 insertions, 8 deletions
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 */