From 78ed9f82ad2813f30f290eb00395206277048c82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Mon, 22 Feb 2010 21:34:43 +0000 Subject: [PATCH 1/1] * first Trim the right end, so we don't need to move stuff around we would later cut * protect us for a bufferunderrun here --- libcitadel/lib/stringbuf.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index fe4913fa4..8048aeb66 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -931,16 +931,20 @@ void StrBufTrim(StrBuf *Buf) int delta = 0; if ((Buf == NULL) || (Buf->BufUsed == 0)) return; + while ((Buf->BufUsed > 0) && + isspace(Buf->buf[Buf->BufUsed - 1])) + { + Buf->BufUsed --; + } + Buf->buf[Buf->BufUsed] = '\0'; + + if (Buf->BufUsed == 0) return; + while ((Buf->BufUsed > delta) && (isspace(Buf->buf[delta]))){ delta ++; } if (delta > 0) StrBufCutLeft(Buf, delta); - if (Buf->BufUsed == 0) return; - while (isspace(Buf->buf[Buf->BufUsed - 1])){ - Buf->BufUsed --; - } - Buf->buf[Buf->BufUsed] = '\0'; } /** -- 2.39.2