diff options
Diffstat (limited to 'string')
-rw-r--r-- | string/strcoll.c | 34 | ||||
-rw-r--r-- | string/strxfrm.c | 20 |
2 files changed, 37 insertions, 17 deletions
diff --git a/string/strcoll.c b/string/strcoll.c index e58b74cf51..6b18567e8a 100644 --- a/string/strcoll.c +++ b/string/strcoll.c @@ -96,16 +96,18 @@ STRCOLL (s1, s2, l) int s1idx = forward ? 0 : s1run->data[pass].number - 1; int s2idx = forward ? 0 : s2run->data[pass].number - 1; - do + while (1) { int s1ignore = 0; int s2ignore = 0; - u_int32_t w1, w2; + u_int32_t w1 = 0; + u_int32_t w2 = 0; /* Here we have to check for IGNORE entries. If these are found we count them and go on with the next value. */ - while ((w1 = s1run->data[pass].value[s1idx]) - == (u_int32_t) IGNORE_CHAR) + while (s1run != NULL + && ((w1 = s1run->data[pass].value[s1idx]) + == (u_int32_t) IGNORE_CHAR)) { ++s1ignore; if ((forward && ++s1idx >= s1run->data[pass].number) @@ -115,15 +117,19 @@ STRCOLL (s1, s2, l) if (nextp == NULL) { w1 = 0; - break; + /* No more non-INGOREd elements means lowest + possible value. */ + s1ignore = -1; } + else + s1idx = forward ? 0 : nextp->data[pass].number - 1; s1run = nextp; - s1idx = forward ? 0 : s1run->data[pass].number - 1; } } - while ((w2 = s2run->data[pass].value[s2idx]) - == (u_int32_t) IGNORE_CHAR) + while (s2run != NULL + && ((w2 = s2run->data[pass].value[s2idx]) + == (u_int32_t) IGNORE_CHAR)) { ++s2ignore; if ((forward && ++s2idx >= s2run->data[pass].number) @@ -133,13 +139,20 @@ STRCOLL (s1, s2, l) if (nextp == NULL) { w2 = 0; - break; + /* No more non-INGOREd elements means lowest + possible value. */ + s2ignore = -1; } + else + s2idx = forward ? 0 : nextp->data[pass].number - 1; s2run = nextp; - s2idx = forward ? 0 : s2run->data[pass].number - 1; } } + /* If one string is completely processed stop. */ + if (s1run == NULL || s2run == NULL) + break; + /* Now we have information of the number of ignored weights and the value of the next weight. */ if ((collate_rules[pass] & sort_position) != 0 @@ -179,7 +192,6 @@ STRCOLL (s1, s2, l) } } - while (s1run != NULL && s2run != NULL); if (s1run != s2run) return s1run != NULL ? 1 : -1; diff --git a/string/strxfrm.c b/string/strxfrm.c index e22738667c..8222adf435 100644 --- a/string/strxfrm.c +++ b/string/strxfrm.c @@ -197,14 +197,16 @@ STRXFRM (STRING_TYPE *dest, const STRING_TYPE *src, size_t n, __locale_t l) const weight_t *run = forward ? forw : backw; int idx = forward ? 0 : run->data[pass].number - 1; - do + while (1) { int ignore = 0; - u_int32_t w; + u_int32_t w = 0; /* Here we have to check for IGNORE entries. If these are found we count them and go on with he next value. */ - while ((w = run->data[pass].value[idx]) == (u_int32_t) IGNORE_CHAR) + while (run != NULL + && ((w = run->data[pass].value[idx]) + == (u_int32_t) IGNORE_CHAR)) { ++ignore; if ((forward && ++idx >= run->data[pass].number) @@ -214,13 +216,20 @@ STRXFRM (STRING_TYPE *dest, const STRING_TYPE *src, size_t n, __locale_t l) if (nextp == NULL) { w = 0; - break; + /* No more non-INGOREd elements means lowest + possible value. */ + ignore = -1; } + else + idx = forward ? 0 : nextp->data[pass].number - 1; run = nextp; - idx = forward ? 0 : run->data[pass].number - 1; } } + /* Stop if all characters are processed. */ + if (run == NULL) + break; + /* Now we have information of the number of ignored weights and the value of the next weight. We have to add 2 because 0 means EOS and 1 is the intermediate string end. */ @@ -245,7 +254,6 @@ STRXFRM (STRING_TYPE *dest, const STRING_TYPE *src, size_t n, __locale_t l) idx = run->data[pass].number - 1; } } - while (run != NULL); /* Write marker for end of word. */ if (pass + 1 < collate_nrules) |