* lib/dfa.c (compare): Avoid integer overflow when analyzing very large regular expressions. --- ChangeLog | 4 ++++ lib/dfa.c | 9 ++------- 2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog index bc912c771..80b4abc5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2019-12-11 Paul Eggert <egg...@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. diff --git a/lib/dfa.c b/lib/dfa.c index 2347a91c1..ca123c68c 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 -- 2.23.0