From a8190734b62d75f73e09c8724bef06702fe5a905 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Thu, 5 Jul 2007 22:56:04 +0000 Subject: [PATCH] * strlen(); strcpy -> single strlen + memmove --- webcit/tools.c | 19 +++++++++++++------ webcit/vcard.c | 14 +++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/webcit/tools.c b/webcit/tools.c index ff11a586b..98c3bb584 100644 --- a/webcit/tools.c +++ b/webcit/tools.c @@ -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 --; + } } diff --git a/webcit/vcard.c b/webcit/vcard.c index 431d57dfc..65dfd1c0f 100644 --- a/webcit/vcard.c +++ b/webcit/vcard.c @@ -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; i0) { + 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; -- 2.30.2