From 01adadf8a90436b4f413c5761e4c2888aa5fb94e Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sun, 5 Mar 2017 09:09:06 +0100 Subject: [PATCH] Fix escape_string returning wrong address escape_string should return the alloc'ed address, not a pointer to the NUL at the end of the string This fixes dc99f8d7a of PR #658 (LemonBoy/dcc-autoaccept) --- src/core/misc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/misc.c b/src/core/misc.c index 03fcce59..9db32aa5 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -728,16 +728,17 @@ int expand_escape(const char **data) char *escape_string(const char *str, const char *what) { const char *p; - char *ret; + char *ret, *escaped; ret = g_malloc(strlen(str) * 2 + 1); - for (p = str; *p != '\0'; p++, ret++) { + escaped = ret; + for (p = str; *p != '\0'; p++, escaped++) { if (strchr(what, *p) != NULL) { - *ret++ = '\\'; + *escaped++ = '\\'; } - *ret = *p; + *escaped = *p; } - *ret = '\0'; + *escaped = '\0'; return ret; }