From f1ea7984bfd8935d90c7e6ce6257ffd9be04c98c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 17 Aug 2005 13:55:55 +0000 Subject: [PATCH] Fix the iterator, so that it ends before the '\0'. --- lib/ChangeLog | 7 +++++++ lib/strcasecmp.c | 11 +++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 394c5c97cc..6fc257347f 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,10 @@ +2005-08-16 Bruno Haible + + * strcasecmp.c (struct mbiter_multi): Remove at_end field. + (mbi_init): Update. + (mbi_avail, mbi_advance): Let the iteration end before the terminating + NUL byte, not after it. + 2005-08-16 Bruno Haible * mbchar.h (mb_cmp, mb_casecmp): Order the invalid characters after diff --git a/lib/strcasecmp.c b/lib/strcasecmp.c index 65a29a9587..e1f414c287 100644 --- a/lib/strcasecmp.c +++ b/lib/strcasecmp.c @@ -30,7 +30,8 @@ #include "strnlen1.h" -/* Like mbiter.h, except it doesn't look at the entire string. */ +/* Like mbiter.h, except it doesn't look at the entire string, only at + very few bytes past the current point. */ #include "mbchar.h" @@ -42,7 +43,6 @@ struct mbiter_multi { - bool at_end; /* true if the end of the string has been reached */ bool in_shift; /* true if next byte may not be interpreted as ASCII */ mbstate_t state; /* if in_shift: current shift state */ bool next_done; /* true if mbi_avail has already filled the following */ @@ -119,14 +119,13 @@ mbiter_multi_next (struct mbiter_multi *iter) /* Iteration macros. */ typedef struct mbiter_multi mbi_iterator_t; #define mbi_init(iter, startptr) \ - ((iter).cur.ptr = (startptr), (iter).at_end = false, \ + ((iter).cur.ptr = (startptr), \ (iter).in_shift = false, memset (&(iter).state, '\0', sizeof (mbstate_t)), \ (iter).next_done = false) #define mbi_avail(iter) \ - (!(iter).at_end && (mbiter_multi_next (&(iter)), true)) + (mbiter_multi_next (&(iter)), !mb_isnul ((iter).cur)) #define mbi_advance(iter) \ - ((mb_isnul ((iter).cur) ? ((iter).at_end = true) : 0), \ - (iter).cur.ptr += (iter).cur.bytes, (iter).next_done = false) + ((iter).cur.ptr += (iter).cur.bytes, (iter).next_done = false) /* Access to the current character. */ #define mbi_cur(iter) (iter).cur -- 2.30.2