]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/tool/tool.c
fix ngt_TrimStr(), fix format string
[ngircd-alex.git] / src / tool / tool.c
index effa640da84ad625e73647d0b361c880e975fdcc..27051ced632cdc5e8280bb11f35c37a79b059082 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: tool.c,v 1.4 2006/03/22 08:05:10 alex Exp $";
+static char UNUSED id[] = "$Id: tool.c,v 1.5 2006/03/24 23:25:39 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -43,16 +43,21 @@ ngt_TrimStr(char *String)
        while (*start == ' ' || *start == '\t')
                start++;
 
+       if (!*start) {
+               *String = 0;
+               return;
+       }
        /* ... and at the end: */
        end = strchr(start, '\0');
+       end--;
        while ((*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r')
-              && end >= start)
+              && end > start)
                end--;
 
        /* New trailing NULL byte */
        *(++end) = '\0';
 
-       memmove(String, start, (size_t)(end - start));
+       memmove(String, start, (size_t)(end - start)+1);
 } /* ngt_TrimStr */