From: Paul Eggert Date: Wed, 11 Dec 2019 21:44:03 +0000 (-0800) Subject: dfa: fix index overflow X-Git-Tag: v1.0~4524 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=d8322e93dcffc94cbdcba81dbf9874fe47b1e1fe;p=gnulib.git dfa: fix index overflow * lib/dfa.c (compare): Avoid integer overflow when analyzing very large regular expressions. --- diff --git a/ChangeLog b/ChangeLog index bc912c771b..80b4abc5bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2019-12-11 Paul Eggert + 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. diff --git a/lib/dfa.c b/lib/dfa.c index 2347a91c13..ca123c68c1 100644 --- 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