summaryrefslogtreecommitdiff
path: root/string
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 /string
parent6145c5ea692b73d2bec98c4cb6ad4012916c005d (diff)
Correct handling of `position' levels with no non-IGNOREd element and
handling of NUL byte.
Diffstat (limited to 'string')
-rw-r--r--string/strcoll.c34
-rw-r--r--string/strxfrm.c22
2 files changed, 38 insertions, 18 deletions
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)