From 09903fa7063d031080f7046fa40ac1c5430dc1ba Mon Sep 17 00:00:00 2001 From: Jan Kneschke Date: Mon, 11 Jul 2005 10:58:27 +0000 Subject: [PATCH] one character was not compared for the string-length was below sizeof(size_t) git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.3.x@437 152afb58-edef-0310-8abb-c4023f1b3aa9 --- src/buffer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 959f9cc4..5c943edb 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -517,15 +517,19 @@ int buffer_is_equal(buffer *a, buffer *b) { if (a->used != b->used) return 0; if (a->used == 0) return 1; - for (i = a->used - 1; i < a->used && i % (sizeof(size_t)); i --) { + /* we are unsigned, if i < 0 it will flip to MAX_SIZE_T and will be > a->used */ + for (i = a->used - 1; i < a->used && i % (sizeof(size_t)); i--) { if (a->ptr[i] != b->ptr[i]) return 0; } + /* compare the single char itself which was kicked us out of the loop */ + if (i < a->used && a->ptr[i] != b->ptr[i]) return 0; + for (i -= (sizeof(size_t)); i < a->used; i -= (sizeof(size_t))) { if (*((size_t *)(a->ptr + i)) != *((size_t *)(b->ptr + i))) return 0; } - + return 1; }