From 947dfda515505f937eac5b388384dd6df0278e40 Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Mon, 9 Nov 2015 18:43:40 +0100 Subject: [PATCH] Refactor strtrim function Signed-off-by: Silvan Jegen Signed-off-by: Allan McRae --- src/common/util-common.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/common/util-common.c b/src/common/util-common.c index 542dcfde..0b67d85a 100644 --- a/src/common/util-common.c +++ b/src/common/util-common.c @@ -144,17 +144,13 @@ size_t strtrim(char *str) } if(pch != str) { size_t len = strlen(pch); - if(len) { - memmove(str, pch, len + 1); - pch = str; - } else { + /* check if there wasn't anything but whitespace in the string. */ + if(len == 0) { *str = '\0'; + return 0; } - } - - /* check if there wasn't anything but whitespace in the string. */ - if(*str == '\0') { - return 0; + memmove(str, pch, len + 1); + pch = str; } end = (str + strlen(str) - 1);