From d8322e93dcffc94cbdcba81dbf9874fe47b1e1fe Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 11 Dec 2019 13:44:03 -0800 Subject: [PATCH] dfa: fix index overflow * 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 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 -- 2.39.5