about summary refs log tree commit diff
path: root/string/strxfrm.c
diff options
context:
space:
mode:
Diffstat (limited to 'string/strxfrm.c')
-rw-r--r--string/strxfrm.c20
1 files changed, 14 insertions, 6 deletions
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)