Fix code to search for \x01 characters (ICU mode)
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 21 Jan 2013 11:23:54 +0000 (12:23 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 21 Jan 2013 11:23:54 +0000 (12:23 +0100)
Avoid constructs using while (--i >= 0 ..) - when i is an unsigned
integer (always true).

index/rpnsearch.c

index b214aef..f5aa669 100644 (file)
@@ -265,13 +265,10 @@ static int term_102_icu(zebra_map_t zm,
                                             &display_buf, &display_len))
                 {
                     size_t i = res_len;
                                             &display_buf, &display_len))
                 {
                     size_t i = res_len;
-                    while (--i >= 0 && res_buf[i] != '\x01')
+                    while (i > 0 && res_buf[--i] != '\x01')
+                        ;
+                    while (i > 0 && res_buf[--i] != '\x01')
                         ;
                         ;
-                    if (i > 0)
-                    {
-                        while (--i >= 0 && res_buf[i] != '\x01')
-                            ;
-                    }
                     res_len = i; /* reduce res_len */
                     for (i = 0; i < res_len; i++)
                     {
                     res_len = i; /* reduce res_len */
                     for (i = 0; i < res_len; i++)
                     {
@@ -348,13 +345,10 @@ static int term_100_icu(zebra_map_t zm,
            may give false hits due to accents not being used.
         */
         i = res_len;
            may give false hits due to accents not being used.
         */
         i = res_len;
-        while (--i >= 0 && res_buf[i] != '\x01')
+        while (i > 0 && res_buf[--i] != '\x01')
+            ;
+        while (i > 0 && res_buf[--i] != '\x01')
             ;
             ;
-        if (i > 0)
-        {
-            while (--i >= 0 && res_buf[i] != '\x01')
-                ;
-        }
         if (i == 0)
         {  /* did not find base chars at all. Throw error */
             return -1;
         if (i == 0)
         {  /* did not find base chars at all. Throw error */
             return -1;