[Groonga-commit] groonga/groonga at a83a107 [master] grn_pat: insert a break to avoid an infinite loop

Back to archive index

susumu.yata null+****@clear*****
Tue Oct 13 12:43:03 JST 2015


susumu.yata	2015-10-13 12:43:03 +0900 (Tue, 13 Oct 2015)

  New Revision: a83a10754026eeae5cd97b6757e4cf48a5838f35
  https://github.com/groonga/groonga/commit/a83a10754026eeae5cd97b6757e4cf48a5838f35

  Message:
    grn_pat: insert a break to avoid an infinite loop
    
    GitHub: #419

  Modified files:
    lib/pat.c

  Modified: lib/pat.c (+40 -39)
===================================================================
--- lib/pat.c    2015-10-13 12:28:29 +0900 (841f40e)
+++ lib/pat.c    2015-10-13 12:43:03 +0900 (67e1f8f)
@@ -1681,49 +1681,50 @@ grn_pat_cursor_next(grn_ctx *ctx, grn_pat_cursor *c)
     int check = se->check, ch;
     while (id) {
       PAT_AT(c->pat, id, node);
-      if (node) {
-        ch = PAT_CHK(node);
-        if (ch > check) {
-          if (c->obj.header.flags & GRN_CURSOR_DESCENDING) {
-            push(c, node->lr[0], ch);
-            id = node->lr[1];
-          } else {
-            push(c, node->lr[1], ch);
-            id = node->lr[0];
-          }
-          check = ch;
-          continue;
+      if (!node) {
+        break;
+      }
+      ch = PAT_CHK(node);
+      if (ch > check) {
+        if (c->obj.header.flags & GRN_CURSOR_DESCENDING) {
+          push(c, node->lr[0], ch);
+          id = node->lr[1];
         } else {
-          if (id == c->tail) {
-            c->sp = 0;
-          } else {
-            if (!c->curr_rec && c->tail) {
-              uint32_t lmin, lmax;
-              pat_node *nmin, *nmax;
-              const uint8_t *kmin, *kmax;
-              if (c->obj.header.flags & GRN_CURSOR_DESCENDING) {
-                PAT_AT(c->pat, c->tail, nmin);
-                PAT_AT(c->pat, id, nmax);
-              } else {
-                PAT_AT(c->pat, id, nmin);
-                PAT_AT(c->pat, c->tail, nmax);
-              }
-              lmin = PAT_LEN(nmin);
-              lmax = PAT_LEN(nmax);
-              kmin = pat_node_get_key(ctx, c->pat, nmin);
-              kmax = pat_node_get_key(ctx, c->pat, nmax);
-              if ((lmin < lmax) ?
-                  (memcmp(kmin, kmax, lmin) > 0) :
-                  (memcmp(kmin, kmax, lmax) >= 0)) {
-                c->sp = 0;
-                break;
-              }
+          push(c, node->lr[1], ch);
+          id = node->lr[0];
+        }
+        check = ch;
+        continue;
+      } else {
+        if (id == c->tail) {
+          c->sp = 0;
+        } else {
+          if (!c->curr_rec && c->tail) {
+            uint32_t lmin, lmax;
+            pat_node *nmin, *nmax;
+            const uint8_t *kmin, *kmax;
+            if (c->obj.header.flags & GRN_CURSOR_DESCENDING) {
+              PAT_AT(c->pat, c->tail, nmin);
+              PAT_AT(c->pat, id, nmax);
+            } else {
+              PAT_AT(c->pat, id, nmin);
+              PAT_AT(c->pat, c->tail, nmax);
+            }
+            lmin = PAT_LEN(nmin);
+            lmax = PAT_LEN(nmax);
+            kmin = pat_node_get_key(ctx, c->pat, nmin);
+            kmax = pat_node_get_key(ctx, c->pat, nmax);
+            if ((lmin < lmax) ?
+                (memcmp(kmin, kmax, lmin) > 0) :
+                (memcmp(kmin, kmax, lmax) >= 0)) {
+              c->sp = 0;
+              break;
             }
           }
-          c->curr_rec = id;
-          c->rest--;
-          return id;
         }
+        c->curr_rec = id;
+        c->rest--;
+        return id;
       }
     }
   }
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index