From: Anthony Minessale Date: Thu, 13 Jan 2011 16:58:53 +0000 (-0600) Subject: FS-2975 X-Git-Tag: v1.2-rc1~203^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6bdb303d43383f4d3474f54e5dbf2b6d699f2bd;p=thirdparty%2Ffreeswitch.git FS-2975 --- diff --git a/src/switch_utils.c b/src/switch_utils.c index 1578e63f9a..0c492525b1 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -809,23 +809,29 @@ SWITCH_DECLARE(char *) switch_strip_whitespace(const char *str) { const char *sp = str; char *p, *s = NULL; + size_t len; - if (!sp) - return NULL; + if (zstr(sp)) { + return (char *) sp; + } while ((*sp == 13 ) || (*sp == 10 ) || (*sp == 9 ) || (*sp == 32) || (*sp == 11) ) { sp++; } + + if (zstr(sp)) { + return (char *) sp; + } s = strdup(sp); + switch_assert(s); - if (!s) - return NULL; - - p = s + (strlen(s) - 1); + if ((len = strlen(s)) > 0) { + p = s + (len - 1); - while ((*p == 13 ) || (*p == 10 ) || (*p == 9 ) || (*p == 32) || (*p == 11) ) { - *p-- = '\0'; + while (p > s && ((*p == 13 ) || (*p == 10 ) || (*p == 9 ) || (*p == 32) || (*p == 11))) { + *p-- = '\0'; + } } return s; @@ -835,9 +841,11 @@ SWITCH_DECLARE(char *) switch_strip_spaces(char *str, switch_bool_t dup) { char *sp = str; char *p, *s = NULL; + size_t len; - if (!sp) - return NULL; + if (zstr(sp)) { + return sp; + } while (*sp == ' ') { sp++; @@ -845,17 +853,21 @@ SWITCH_DECLARE(char *) switch_strip_spaces(char *str, switch_bool_t dup) if (dup) { s = strdup(sp); + switch_assert(s); } else { s = sp; } - if (!s) - return NULL; + if (zstr(s)) { + return s; + } - p = s + (strlen(s) - 1); + if ((len = strlen(s)) > 0) { + p = s + (len - 1); - while (*p == ' ') { - *p-- = '\0'; + while (p && *p && p > s && *p == ' ') { + *p-- = '\0'; + } } return s;