* strlen(); strcpy -> single strlen + memmove
authorWilfried Göesgens <willi@citadel.org>
Thu, 5 Jul 2007 22:56:04 +0000 (22:56 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 5 Jul 2007 22:56:04 +0000 (22:56 +0000)
webcit/tools.c
webcit/vcard.c

index ff11a586b332d6d2e4df93bff7c2b2f8848b3d02..98c3bb584a8405d8fe61024223d03bfa6926326b 100644 (file)
@@ -249,12 +249,19 @@ int pattern2(char *search, char *patn)
  */
 void striplt(char *buf)
 {
-       if (strlen(buf) == 0) return;
-       while ((strlen(buf) > 0) && (isspace(buf[0])))
-               strcpy(buf, &buf[1]);
-       if (strlen(buf) == 0) return;
-       while (isspace(buf[strlen(buf) - 1]))
-               buf[strlen(buf) - 1] = 0;
+       long len;
+
+       len = strlen(buf);
+       if (len == 0) return;
+       while ((len > 0) && (isspace(buf[0]))){
+               memmove (buf, &buf[1], len);
+               len --;
+       }
+       if (len == 0) return;
+       while (isspace(buf[len - 1])){
+               buf[len - 1] = 0;
+               len --;
+       }
 }
 
 
index 431d57dfceee86138fc3e3aba63db960d05271cd..65dfd1c0fc5cbd632eb0b1f0fac6c2ab2a5cb25e 100644 (file)
@@ -84,6 +84,7 @@ struct vCard *vcard_load(char *vtext) {
        char *mycopy, *ptr;
        char *namebuf, *valuebuf;
        int i;
+       int len;
        int colonpos, nlpos;
 
        if (vtext == NULL) return vcard_new();
@@ -95,12 +96,15 @@ struct vCard *vcard_load(char *vtext) {
         * To make it easier to parse, we convert CRLF to LF, and unfold any
         * multi-line fields into single lines.
         */
-       for (i=0; i<strlen(mycopy); ++i) {
+       len = strlen(mycopy);
+       for (i=0; i<len; ++i) {
                if (!strncmp(&mycopy[i], "\r\n", 2)) {
-                       strcpy(&mycopy[i], &mycopy[i+1]);
+                       memmove(&mycopy[i], &mycopy[i+1], len - i);
+                       len --;
                }
                if ( (mycopy[i]=='\n') && (isspace(mycopy[i+1])) ) {
-                       strcpy(&mycopy[i], &mycopy[i+1]);
+                       memmove(&mycopy[i], &mycopy[i+1], len - i);
+                       len --;
                }
        }
 
@@ -108,7 +112,7 @@ struct vCard *vcard_load(char *vtext) {
        if (v == NULL) return v;
 
        ptr = mycopy;
-       while (strlen(ptr)>0) {
+       while (*ptr != '\0') {
                colonpos = (-1);
                nlpos = (-1);
                colonpos = pattern2(ptr, ":");
@@ -147,7 +151,7 @@ struct vCard *vcard_load(char *vtext) {
 
                }
 
-               while ( (*ptr != '\n') && (strlen(ptr)>0) ) {
+               while ( (*ptr != '\n') && (*ptr != '\0') ) {
                        ++ptr;
                }
                if (*ptr == '\n') ++ptr;