From 0d52f4c0fc5de39e368c6b093d538bfe8e81ae1b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sat, 6 Oct 2007 09:11:44 +0000 Subject: [PATCH] * strip blanks / whitespaces more effectively * zero string before using it to make valgrind shut up. --- citadel/support.c | 14 +++++++++----- citadel/tools.c | 14 ++++++++++---- citadel/user_ops.c | 1 + 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/citadel/support.c b/citadel/support.c index a3ebffc19..8a56d8544 100644 --- a/citadel/support.c +++ b/citadel/support.c @@ -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) { diff --git a/citadel/tools.c b/citadel/tools.c index 4e1129a73..4a5e4cac0 100644 --- a/citadel/tools.c +++ b/citadel/tools.c @@ -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); } diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 20aa372d2..f457c6089 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -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, -- 2.39.2