don't let ast_trim_blanks operate on empty strings or run off the beginning of the...
authorKevin P. Fleming <kpfleming@digium.com>
Fri, 17 Jun 2005 14:27:57 +0000 (14:27 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Fri, 17 Jun 2005 14:27:57 +0000 (14:27 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5929 65c4cc65-6c06-0410-ace0-fbb531ad65f3

utils.c

diff --git a/utils.c b/utils.c
index 7f50c7b..7768538 100755 (executable)
--- a/utils.c
+++ b/utils.c
@@ -46,13 +46,15 @@ char *ast_skip_blanks(char *str)
  
 char *ast_trim_blanks(char *str)
 {
  
 char *ast_trim_blanks(char *str)
 {
-       if (str) {
-               str += strlen(str) - 1;
-               while (*str && *str < 33)
-                       str--;
-               *(++str) = '\0'; /* terminate string */
+       char *work = str;
+
+       if (work && !ast_strlen_zero(work)) {
+               work += strlen(work) - 1;
+               while ((work >= str) && *work && *work < 33)
+                       work--;
+               *(++work) = '\0'; /* terminate string */
        }
        }
-       return str;
+       return work;
 }
 
 char *ast_skip_nonblanks(char *str)
 }
 
 char *ast_skip_nonblanks(char *str)