* strip blanks / whitespaces more effectively
authorWilfried Göesgens <willi@citadel.org>
Sat, 6 Oct 2007 09:11:44 +0000 (09:11 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 6 Oct 2007 09:11:44 +0000 (09:11 +0000)
* zero string before using it to make valgrind shut up.

citadel/support.c
citadel/tools.c
citadel/user_ops.c

index a3ebffc19142e7bb6d52288160b0011f25df099d..8a56d85445cf7d3e517f46aae6ff3f7db6ede610 100644 (file)
@@ -23,7 +23,7 @@
  */
 void strproc(char *string)
 {
-       int a;
+       int a, b;
 
        if (string == NULL) return;
        if (IsEmptyStr(string)) return;
@@ -34,11 +34,15 @@ void strproc(char *string)
                if (string[a]>126) string[a]=32;
        }
 
+       /* a is now the length of our string. */
        /* Remove leading and trailing blanks */
-       while( (string[0]<33) && (!IsEmptyStr(string)) )
-               strcpy(string,&string[1]);
-       while( (string[strlen(string)-1]<33) && (!IsEmptyStr(string)) )
-               string[strlen(string)-1]=0;
+       while( (string[a-1]<33) && (!IsEmptyStr(string)) )
+               string[--a]=0;
+       b = 0;
+       while( (string[b]<33) && (!IsEmptyStr(&string[b])) )
+               b++;
+       if (b > 0)
+               memmove(string,&string[b], a - b + 1);
 
        /* Remove double blanks */
        for (a=0; !IsEmptyStr(&string[a]); ++a) {
index 4e1129a731a72ca39e0a68af74b9f32f0d5622d8..4a5e4cac0fa0a24305fcdf9469e38e1840be7654 100644 (file)
@@ -440,12 +440,18 @@ char *rfc2047encode(char *line, long length)
  */
 void striplt(char *buf)
 {
+       size_t len;
+       int a;
        if (IsEmptyStr(buf)) return;
-        while ((!IsEmptyStr(buf)) && (isspace(buf[0])))
-                strcpy(buf, &buf[1]);
+       len = strlen(buf);
+        while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
+                buf[--len] = 0;
        if (IsEmptyStr(buf)) return;
-        while ((!IsEmptyStr(buf)) && (isspace(buf[strlen(buf) - 1])))
-                buf[strlen(buf) - 1] = 0;
+       a = 0;
+        while ((!IsEmptyStr(buf)) && (isspace(buf[a])))
+               a++;
+       if (a > 0)
+                memmove(buf, &buf[a], len - a + 1);
 }
 
 
index 20aa372d234894c89350c93086808e749a05293f..f457c60894f7795e1a40fef116a81ce957dd5e98 100644 (file)
@@ -180,6 +180,7 @@ void put_visit(struct visit *newvisit)
        char IndexBuf[32];
        int IndexLen = 0;
 
+       memset (IndexBuf, 0, sizeof (IndexBuf));
        /* Generate an index */
        IndexLen = GenerateRelationshipIndex(IndexBuf,
                                             newvisit->v_roomnum,