It took me a few minutes to convince myself that a coverity warning
was unwarranted, so I've added an assert that should suppress it.

If someone sees a better way (i.e., with no assertion), please suggest a patch.
From 744c745300fa7b1c73dd9f6b323d3bf4823857e6 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyer...@fb.com>
Date: Mon, 12 Dec 2016 21:12:14 -0800
Subject: [PATCH] dfa: add an assertion to avoid coverity false positive

* lib/dfa.c (realloc_trans_if_necessary): Otherwise, coverity
warned that "newalloc1 - 2" could overflow.
---
 ChangeLog | 6 ++++++
 lib/dfa.c | 1 +
 2 files changed, 7 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 8f1671a..69be242 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-12-12  Jim Meyering  <meyer...@fb.com>
+
+       dfa: add an assertion to avoid coverity false positive
+       * lib/dfa.c (realloc_trans_if_necessary): Otherwise, coverity
+       warned that "newalloc1 - 2" could overflow.
+
 2016-12-13   Arnold D. Robbins  <arn...@skeeve.com>

        dfa: remove DFA_CASE_FOLD flag in favor of RE_ICASE
diff --git a/lib/dfa.c b/lib/dfa.c
index 6fee7a1..c29dd02 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -2778,6 +2778,7 @@ realloc_trans_if_necessary (struct dfa *d, state_num 
new_state)
       realtrans = x2nrealloc (realtrans, &newalloc1, sizeof *realtrans);
       realtrans[0] = realtrans[1] = NULL;
       d->trans = realtrans + 2;
+      assert (2 <= newalloc1);
       d->tralloc = newalloc = newalloc1 - 2;
       d->fails = xnrealloc (d->fails, newalloc, sizeof *d->fails);
       d->success = xnrealloc (d->success, newalloc, sizeof *d->success);
-- 
2.9.3

Reply via email to