From e918187f565eac1aeed2c0e8fb32893ef3bb2143 Mon Sep 17 00:00:00 2001
From: Mike Palmiotto <mike.palmiotto@crunchydata.com>
Date: Tue, 28 Mar 2017 16:44:54 +0000
Subject: [PATCH 1/2] Silence some sepgsql compiler warnings

selinux/label.h includes stdbool.h, which redefines the bool type and results in
a warning: assignment from incompatible pointer type for sepgsql_fmgr_hook. Make
sure we clean up the bool definition after label.h is included.

Additionally, sepgsql throws compiler warnings due to possibly uninitialized
tclass in code paths for indexes. Set tclass to a PG_UINT16_MAX (undefined) to
silence these warnings.
---
 contrib/sepgsql/label.c    | 12 ++++++++++--
 contrib/sepgsql/relation.c | 10 ++++++++--
 contrib/sepgsql/sepgsql.h  |  2 +-
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/contrib/sepgsql/label.c b/contrib/sepgsql/label.c
index 1a8f884..8a72503 100644
--- a/contrib/sepgsql/label.c
+++ b/contrib/sepgsql/label.c
@@ -10,6 +10,16 @@
  */
 #include "postgres.h"
 
+#include <selinux/label.h>
+
+/*
+ * Fix for stdbool.h re-definition of bool type
+ */
+#ifdef bool
+#undef bool
+typedef char bool;
+#endif
+
 #include "access/heapam.h"
 #include "access/htup_details.h"
 #include "access/genam.h"
@@ -37,8 +47,6 @@
 
 #include "sepgsql.h"
 
-#include <selinux/label.h>
-
 /*
  * Saved hook entries (if stacked)
  */
diff --git a/contrib/sepgsql/relation.c b/contrib/sepgsql/relation.c
index ab98a9b..4dc48a0 100644
--- a/contrib/sepgsql/relation.c
+++ b/contrib/sepgsql/relation.c
@@ -300,8 +300,11 @@ sepgsql_relation_post_create(Oid relOid)
 			tclass = SEPG_CLASS_DB_VIEW;
 			break;
 		case RELKIND_INDEX:
-			/* deal with indexes specially; no need for tclass */
+			/* other indexes are handled specially below; set tclass to
+			 * "undefined" to silence compiler warning
+			 */
 			sepgsql_index_modify(relOid);
+			tclass = SEPG_CLASS_UNDEFINED;
 			goto out;
 		default:
 			/* ignore other relkinds */
@@ -432,7 +435,10 @@ sepgsql_relation_drop(Oid relOid)
 			/* ignore indexes on toast tables */
 			if (get_rel_namespace(relOid) == PG_TOAST_NAMESPACE)
 				return;
-			/* other indexes are handled specially below; no need for tclass */
+			/* other indexes are handled specially below; set tclass to
+			 * "undefined" to silence compiler warning
+			 */
+			tclass = SEPG_CLASS_UNDEFINED;
 			break;
 		default:
 			/* ignore other relkinds */
diff --git a/contrib/sepgsql/sepgsql.h b/contrib/sepgsql/sepgsql.h
index 9d245c2..ec6fdd8 100644
--- a/contrib/sepgsql/sepgsql.h
+++ b/contrib/sepgsql/sepgsql.h
@@ -52,7 +52,7 @@
 #define SEPG_CLASS_DB_LANGUAGE		16
 #define SEPG_CLASS_DB_VIEW			17
 #define SEPG_CLASS_MAX				18
-
+#define SEPG_CLASS_UNDEFINED		PG_UINT16_MAX
 /*
  * Internally used code of access vectors
  */
-- 
1.8.3.1

