Subject: bug#24564: FYI: port to OpenBSD 5.1 and placate GCC 7's new -Wimplicit-fallthrough

From: Jim Meyering <[email-masked]>
Date: Wed, 28 Sep 2016 22:20:10 -0700

This is mainly to fix a build-failure on openbsd 5.1 reported by
Nelson Beebe, but I have also made changes to ensure grep and all its
dependencies (i.e., gnulib) build with warnings enabled when using the
development (built-from-git) GCC 7.
From 0e1f38d1402abcfbd9dec29103c68f86609ed28c Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email-masked]>
Date: Wed, 28 Sep 2016 11:53:31 -0700
Subject: [PATCH 1/2] gnulib: update to latest; for ...

This includes the following:
 - a getprogname-vs-openbsd-5.1 portability fix
 - "fallthru" comment-adding changes for dfa and unistr/u8-uctomb-aux.c
 - another getprograme fix to avoid breaking newer glibc
---
 gnulib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gnulib b/gnulib
index fce9b3f..5f7358c 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit fce9b3f0e2b98e386ca881a0961ca03e86ce73c8
+Subproject commit 5f7358cc193d40a8e2c37409d437d7f0f2a0f9b1
-- 
2.7.4

From f2751efd87c91576fcac1033a5919d363967a838 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email-masked]>
Date: Wed, 28 Sep 2016 22:08:07 -0700
Subject: [PATCH 2/2] build: placate GCC 7's -Wimplicit-fallthrough

* src/pcresearch.c (die): New macro.
(Pexecute): Use it in place of offending uses of error,
to placate GCC 7's -Wimplicit-fallthrough.
Include verify.h.  Since this is grep's first explicit use of this
gnulib module, ...
* bootstrap.conf (gnulib_modules): Add verify.
---
 bootstrap.conf   |  1 +
 src/pcresearch.c | 19 ++++++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 3b12061..5ee69cd 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -88,6 +88,7 @@ unistd
 unlocked-io
 update-copyright
 useless-if-before-free
+verify
 version-etc-fsf
 wchar
 wcrtomb
diff --git a/src/pcresearch.c b/src/pcresearch.c
index 9ffa22a..6e192e3 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -20,6 +20,19 @@

 #include <config.h>
 #include "search.h"
+#include "verify.h"
+
+/* Wrap a fatal 3-argument use of "error" (with literal nonzero exit
+   status), so that static analyzers like clang-analyzer and GCC 7's
+   -Wimplicit-fallthrough know this "function" does not return.  */
+#define die(st, fmt, arg)						\
+  do									\
+    {									\
+      verify ((st) != 0);						\
+      error (0, fmt, arg);						\
+      exit (st);							\
+    }									\
+  while (0)

 #if HAVE_LIBPCRE
 # include <pcre.h>
@@ -337,15 +350,15 @@ Pexecute (char *buf, size_t size, size_t *match_size,
           break;

         case PCRE_ERROR_NOMEMORY:
-          error (EXIT_TROUBLE, 0, _("memory exhausted"));
+          die (EXIT_TROUBLE, 0, _("memory exhausted"));

 # if PCRE_STUDY_JIT_COMPILE
         case PCRE_ERROR_JIT_STACKLIMIT:
-          error (EXIT_TROUBLE, 0, _("exhausted PCRE JIT stack"));
+          die (EXIT_TROUBLE, 0, _("exhausted PCRE JIT stack"));
 # endif

         case PCRE_ERROR_MATCHLIMIT:
-          error (EXIT_TROUBLE, 0, _("exceeded PCRE's backtracking limit"));
+          die (EXIT_TROUBLE, 0, _("exceeded PCRE's backtracking limit"));

         default:
           /* For now, we lump all remaining PCRE failures into this basket.
-- 
2.7.4