grs1: avoid term_len < 0 for .abs operator 'range'
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 4 Mar 2010 10:25:59 +0000 (11:25 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 4 Mar 2010 10:26:47 +0000 (11:26 +0100)
A negative term_len could happen for Zebra in many releases but it
only reveals itself in YAZ 4 where WRBUF uses size_t length.

index/recgrs.c

index a481e1d..500a0b1 100644 (file)
@@ -104,12 +104,18 @@ static int sp_range(struct source_parser *sp, data1_node *n, RecWord *wrd)
        return 0;       
     sp_lex(sp);
     
-    if (wrd->term_buf && wrd->term_len)
+    if (wrd->term_buf)
     {
-       wrd->term_buf += start;
-       wrd->term_len -= start;
-       if (wrd->term_len > len)
-           wrd->term_len = len;
+        if (start >= wrd->term_len)
+            wrd->term_len = 0;
+        else
+        {
+            wrd->term_len -= start;
+            wrd->term_buf += start;
+
+            if (wrd->term_len > len)
+                wrd->term_len = len;
+        }
     }
     return 1;
 }
@@ -563,7 +569,7 @@ static void index_xpath(struct source_parser *sp, data1_node *n,
                memcpy(&wrd_tl, wrd, sizeof(*wrd));
                if (tl->source)
                    sp_parse(sp, n, &wrd_tl, tl->source);
-                
+
                 /* this is just the old fashioned attribute based index */
                 wrd_tl.index_name = tl->index_name;
                 if (p->flagShowRecords)