]> Savannah Git Hosting - gnulib.git/commitdiff
dfa: fix index overflow
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 11 Dec 2019 21:44:03 +0000 (13:44 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 11 Dec 2019 23:09:38 +0000 (15:09 -0800)
* lib/dfa.c (compare): Avoid integer overflow when analyzing
very large regular expressions.

ChangeLog
lib/dfa.c

index bc912c771bafd127903d062e82c9a2d56f59fdb8..80b4abc5bce73af0749e69dd542da57b75aa02d7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2019-12-11  Paul Eggert  <eggert@cs.ucla.edu>
 
+       dfa: fix index overflow
+       * lib/dfa.c (compare): Avoid integer overflow when analyzing
+       very large regular expressions.
+
        dfa: update commentary for previous change
        * NEWS: Mention the change.
        * lib/dfa.c, lib/dfa.h (dfaparse, dfamust, dfacomp): Update comments.
index 2347a91c133da5f9c6babc53ce7f0d504242d446..ca123c68c13d8f26db5ddeadbc0e91e580c6aa6f 100644 (file)
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -2423,13 +2423,8 @@ merge_nfa_state (struct dfa *d, size_t tindex, char *flags,
 static int
 compare (const void *a, const void *b)
 {
-  int aindex;
-  int bindex;
-
-  aindex = (int) ((position *) a)->index;
-  bindex = (int) ((position *) b)->index;
-
-  return aindex - bindex;
+  position const *p = a, *q = b;
+  return p->index < q->index ? -1 : p->index > q->index;
 }
 
 static void