6c1aee8
commit ae81be0024ea4eaf139b7ba57e9a8ce9e4a163ec
6c1aee8
Author: Jim Meyering <jim@meyering.net>
6c1aee8
Date:   Fri Apr 6 17:17:11 2018 -0700
6c1aee8
6c1aee8
    maint: avoid warnings from GCC8
6c1aee8
    
6c1aee8
    Hi Andreas,
6c1aee8
    
6c1aee8
    I configured with --enable-gcc-warnings and bleeding-edge gcc
6c1aee8
    (version 8.0.1 20180406) and hit some warning-escalated-to-errors.
6c1aee8
    This fixes them:
6c1aee8
    
6c1aee8
    >From a71ddb200dbe7ac0f9258796b5a51979b2740e88 Mon Sep 17 00:00:00 2001
6c1aee8
    From: Jim Meyering <meyering@fb.com>
6c1aee8
    Date: Fri, 6 Apr 2018 16:47:00 -0700
6c1aee8
    Subject: [PATCH] maint: avoid warnings from GCC8
6c1aee8
    
6c1aee8
    * src/common.h (FALLTHROUGH): Define.
6c1aee8
    * src/patch.c (abort_hunk_context): Use FALLTHROUGH macro in place of
6c1aee8
    a comment.  This avoids a warning from -Wimplicit-fallthrough=.
6c1aee8
    * src/pch.c (do_ed_script): Add otherwise unnecessary initialization
6c1aee8
    to avoid warning from -Wmaybe-uninitialized.
6c1aee8
    (another_hunk): Use FALLTHROUGH macro here, too, twice.
6c1aee8
6c1aee8
diff --git a/src/common.h b/src/common.h
6c1aee8
index ec50b40..904a3f8 100644
6c1aee8
--- a/src/common.h
6c1aee8
+++ b/src/common.h
6c1aee8
@@ -218,3 +218,11 @@ bool merge_hunk (int hunk, struct outstate *, lin where, bool *);
6c1aee8
 #else
6c1aee8
 # define merge_hunk(hunk, outstate, where, somefailed) false
6c1aee8
 #endif
6c1aee8
+
6c1aee8
+#ifndef FALLTHROUGH
6c1aee8
+# if __GNUC__ < 7
6c1aee8
+#  define FALLTHROUGH ((void) 0)
6c1aee8
+# else
6c1aee8
+#  define FALLTHROUGH __attribute__ ((__fallthrough__))
6c1aee8
+# endif
6c1aee8
+#endif
6c1aee8
diff --git a/src/patch.c b/src/patch.c
6c1aee8
index 0fe6d72..1ae91d9 100644
6c1aee8
--- a/src/patch.c
6c1aee8
+++ b/src/patch.c
6c1aee8
@@ -1381,7 +1381,7 @@ abort_hunk_context (bool header, bool reverse)
6c1aee8
 	    break;
6c1aee8
 	case ' ': case '-': case '+': case '!':
6c1aee8
 	    fprintf (rejfp, "%c ", pch_char (i));
6c1aee8
-	    /* fall into */
6c1aee8
+	    FALLTHROUGH;
6c1aee8
 	case '\n':
6c1aee8
 	    pch_write_line (i, rejfp);
6c1aee8
 	    break;
6c1aee8
diff --git a/src/pch.c b/src/pch.c
6c1aee8
index 1055542..cda3dfa 100644
6c1aee8
--- a/src/pch.c
6c1aee8
+++ b/src/pch.c
6c1aee8
@@ -1735,7 +1735,7 @@ another_hunk (enum diff difftype, bool rev)
6c1aee8
 		break;
6c1aee8
 	    case '=':
6c1aee8
 		ch = ' ';
6c1aee8
-		/* FALL THROUGH */
6c1aee8
+		FALLTHROUGH;
6c1aee8
 	    case ' ':
6c1aee8
 		if (fillsrc > p_ptrn_lines) {
6c1aee8
 		    free(s);
6c1aee8
@@ -1756,7 +1756,7 @@ another_hunk (enum diff difftype, bool rev)
6c1aee8
 		    p_end = fillsrc-1;
6c1aee8
 		    return -1;
6c1aee8
 		}
6c1aee8
-		/* FALL THROUGH */
6c1aee8
+		FALLTHROUGH;
6c1aee8
 	    case '+':
6c1aee8
 		if (filldst > p_end) {
6c1aee8
 		    free(s);
6c1aee8
@@ -2394,8 +2394,7 @@ do_ed_script (char const *inname, char const *outname,
6c1aee8
     size_t chars_read;
6c1aee8
     FILE *tmpfp = 0;
6c1aee8
     char const *tmpname;
6c1aee8
-    int tmpfd;
6c1aee8
-    pid_t pid;
6c1aee8
+    int tmpfd = -1; /* placate gcc's -Wmaybe-uninitialized */
6c1aee8
     int exclusive = *outname_needs_removal ? 0 : O_EXCL;
6c1aee8
     char const **ed_argv;
6c1aee8
     int stdin_dup, status;