From 913c4e9f1445cd8e10b9342def39eee2a29dcfd0 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 17 Apr 2001 05:05:37 +0000 Subject: [PATCH] ChangeLog, subst.c: subst.c (replace_string): Fix replace_string so that it correctly handles replacing a substitution variable with a zero-length string. --- util/ChangeLog | 6 ++++++ util/subst.c | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/util/ChangeLog b/util/ChangeLog index 9ffa0a9..9cdee1d 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,9 @@ +2001-04-17 Theodore Tso + + * subst.c (replace_string): Fix replace_string so that it + correctly handles replacing a substitution variable with a + zero-length string. + 2001-01-14 Theodore Ts'o * gcc-wall-cleanup: Remove additional annoying warning messages diff --git a/util/subst.c b/util/subst.c index 94444ca..7b7ba83 100644 --- a/util/subst.c +++ b/util/subst.c @@ -108,7 +108,9 @@ static void replace_string(char *begin, char *end, char *newstr) replace_len = strlen(newstr); len = end - begin; - if (replace_len != len+1) + if (replace_len == 0) + memmove(begin, end+1, strlen(end)+1); + else if (replace_len != len+1) memmove(end+(replace_len-len-1), end, strlen(end)+1); memcpy(begin, newstr, replace_len); @@ -248,7 +250,7 @@ static void parse_config_file(FILE *f) if (!isspace(*cp)) break; #if 0 - printf("Substitute: '%s' for '%s'\n", ptr, cp); + printf("Substitute: '%s' for '%s'\n", ptr, cp ? cp : ""); #endif add_subst(ptr, cp); } -- 1.8.3.1