From c5982a3eb5287afdec6c9b859f81795c773da8fe Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 25 Aug 2011 17:14:19 -0500 Subject: strtrim: don't move empty string There were many cases where the string coming in was a blank line, e.g. "\n\0", length 1. The trim routine starts by trimming leading spaces, thus trimming everything. We would then proceed to do a memmove of the NULL byte, which is completely worthless as we can just assign it instead. Signed-off-by: Dan McGee --- lib/libalpm/util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/libalpm/util.c') diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 7e3bc372..cf783893 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -192,7 +192,12 @@ char *_alpm_strtrim(char *str) pch++; } if(pch != str) { - memmove(str, pch, (strlen(pch) + 1)); + size_t len = strlen(pch); + if(len) { + memmove(str, pch, len + 1); + } else { + *str = '\0'; + } } /* check if there wasn't anything but whitespace in the string. */ -- cgit v1.2.3-24-g4f1b