summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-03-05 20:28:57 +0000
committerUlrich Drepper <drepper@redhat.com>1997-03-05 20:28:57 +0000
commit992b2c400be6be16479c956003833fe0a05f1d7a (patch)
tree3161a39e3deabac2a4a4f669a1e204adb5f096e8
parent6145c5ea692b73d2bec98c4cb6ad4012916c005d (diff)
Correct handling of `position' levels with no non-IGNOREd element and
handling of NUL byte.
-rw-r--r--locale/weight.h16
-rw-r--r--string/strcoll.c34
-rw-r--r--string/strxfrm.c22
3 files changed, 45 insertions, 27 deletions
diff --git a/locale/weight.h b/locale/weight.h
index 424e493209..ef767bac59 100644
--- a/locale/weight.h
+++ b/locale/weight.h
@@ -55,8 +55,8 @@ typedef struct weight_t
((u_int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_RULES))
-static __inline int get_weight (const STRING_TYPE **str, weight_t *result);
-static __inline int
+static __inline void get_weight (const STRING_TYPE **str, weight_t *result);
+static __inline void
get_weight (const STRING_TYPE **str, weight_t *result)
{
unsigned int ch = *((USTRING_TYPE *) (*str))++;
@@ -86,7 +86,7 @@ get_weight (const STRING_TYPE **str, weight_t *result)
result->data[cnt].value = &__collate_extra[idx];
idx += result->data[cnt].number;
}
- return 0;
+ return;
}
slot += level_size;
}
@@ -102,7 +102,7 @@ get_weight (const STRING_TYPE **str, weight_t *result)
result->data[cnt].number = 1;
result->data[cnt].value = &__collate_table[slot + 1 + cnt];
}
- return ch == 0;
+ return;
}
/* We now look for any collation element which starts with CH.
@@ -135,14 +135,12 @@ get_weight (const STRING_TYPE **str, weight_t *result)
result->data[cnt].value = &__collate_extra[idx];
idx += result->data[cnt].number;
}
- return 0;
+ return;
}
/* To next entry in list. */
slot += __collate_extra[slot];
}
- /* NOTREACHED */
- return 0; /* To calm down gcc. */
}
@@ -155,7 +153,7 @@ get_weight (const STRING_TYPE **str, weight_t *result)
do \
{ \
weight_t *newp; \
- do \
+ while (*str != '\0') \
{ \
newp = (weight_t *) alloca (sizeof (weight_t) \
+ (collate_nrules \
@@ -168,7 +166,7 @@ get_weight (const STRING_TYPE **str, weight_t *result)
backw->next = newp; \
newp->next = NULL; \
backw = newp; \
+ get_weight (&str, newp); \
} \
- while (get_weight (&str, newp) == 0); \
} \
while (0)
diff --git a/string/strcoll.c b/string/strcoll.c
index aae5944771..c147e51f4b 100644
--- a/string/strcoll.c
+++ b/string/strcoll.c
@@ -67,16 +67,18 @@ STRCOLL (s1, s2)
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)
@@ -86,15 +88,19 @@ STRCOLL (s1, s2)
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)
@@ -104,13 +110,20 @@ STRCOLL (s1, s2)
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
@@ -150,7 +163,6 @@ STRCOLL (s1, s2)
}
}
- while (s1run != NULL && s2run != NULL);
if (s1run != s2run)
return s1run != NULL ? 1 : -1;
diff --git a/string/strxfrm.c b/string/strxfrm.c
index 820ad93947..4076ebb920 100644
--- a/string/strxfrm.c
+++ b/string/strxfrm.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
@@ -172,14 +172,16 @@ STRXFRM (STRING_TYPE *dest, const STRING_TYPE *src, size_t n)
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)
@@ -189,13 +191,20 @@ STRXFRM (STRING_TYPE *dest, const STRING_TYPE *src, size_t n)
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. */
@@ -220,7 +229,6 @@ STRXFRM (STRING_TYPE *dest, const STRING_TYPE *src, size_t n)
idx = run->data[pass].number - 1;
}
}
- while (run != NULL);
/* Write marker for end of word. */
if (pass + 1 < collate_nrules)