resolve stricter warnings

In order to convert this repository to Meson, we need to make it
compile under `warning_level=3`.  Fix a number of warning classes
across the repository or disable them.

Some fixes are:

* Add missing header files.
* Fully initialize structs as necessary.
* Add `__attribute__((unused))` on parameters as necessary.
* Fix comparisons between signed and unsigned.
* Fix printf specifiers as necessary.
* Avoid case-fallthrough.
* Remove if conditions which are always true.

Some warnings would require extensive code changes, due to their
pervasive use, and so are disabled at a per-file level:
* `-Wpointer-arith`
* `-Wunused-result`

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: If8992b9108f12b39f796ed090ba29868c9f3c627
diff --git a/backend.h b/backend.h
index 2433c91..59a6201 100644
--- a/backend.h
+++ b/backend.h
@@ -8,6 +8,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <stdbool.h>
+#include <stddef.h>
 #include <stdint.h>
 #include <mtd/mtd-abi.h>
 
@@ -269,13 +270,13 @@
 #else
 static inline struct backend backend_get_vpnor(void)
 {
-	struct backend be = { 0 };
+	struct backend be = { NULL, NULL, 0, 0, 0 };
 
 	return be;
 }
 
-static inline int backend_probe_vpnor(struct backend *master,
-				      const struct vpnor_partition_paths *paths)
+static inline int backend_probe_vpnor(struct backend *master __attribute__((unused)),
+				      const struct vpnor_partition_paths *paths __attribute__((unused)))
 {
 	return -ENOTSUP;
 }
diff --git a/control.c b/control.c
index 4f472f1..b49d25e 100644
--- a/control.c
+++ b/control.c
@@ -11,7 +11,7 @@
 #include "protocol.h"
 #include "windows.h"
 
-int control_ping(struct mbox_context *context)
+int control_ping(struct mbox_context *context __attribute__((unused)))
 {
 	return 0;
 }
diff --git a/control_dbus.c b/control_dbus.c
index 4fb9e33..f463d69 100644
--- a/control_dbus.c
+++ b/control_dbus.c
@@ -13,7 +13,7 @@
 typedef int (*control_action)(struct mbox_context *context);
 
 static int control_dbus_directive(sd_bus_message *m, void *userdata,
-					sd_bus_error *ret_error,
+					sd_bus_error *ret_error __attribute__((unused)),
 					control_action action)
 {
 	struct mbox_context *context;
@@ -22,7 +22,7 @@
 
 	if (!action) {
 		MSG_ERR("No action provided\n");
-		return -EINVAL; 
+		return -EINVAL;
 	}
 
 	context = (struct mbox_context *) userdata;
@@ -79,7 +79,7 @@
 }
 
 static int control_dbus_resume(sd_bus_message *m, void *userdata,
-				     sd_bus_error *ret_error)
+			       sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context;
 	sd_bus_message *n;
@@ -112,7 +112,7 @@
 }
 
 static int control_dbus_set_backend(sd_bus_message *m, void *userdata,
-				    sd_bus_error *ret_error)
+				    sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context;
 	struct backend backend;
@@ -197,10 +197,12 @@
 	return rc;
 }
 
-static int control_dbus_get_u8(sd_bus *bus, const char *path,
-			       const char *interface, const char *property,
+static int control_dbus_get_u8(sd_bus *bus __attribute__((unused)),
+			       const char *path,
+			       const char *interface __attribute__((unused)),
+			       const char *property,
 			       sd_bus_message *reply, void *userdata,
-			       sd_bus_error *ret_error)
+			       sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context = userdata;
 	uint8_t value;
diff --git a/control_legacy.c b/control_legacy.c
index 2a3461d..c76d1c8 100644
--- a/control_legacy.c
+++ b/control_legacy.c
@@ -41,8 +41,8 @@
  * Resp: NONE
  */
 static int control_legacy_ping(struct mbox_context *context,
-			   struct mbox_dbus_msg *req,
-			   struct mbox_dbus_msg *resp)
+			   struct mbox_dbus_msg *req __attribute__((unused)),
+			   struct mbox_dbus_msg *resp __attribute__((unused)))
 {
 	return control_ping(context);
 }
@@ -55,7 +55,7 @@
  * Resp[0]: Status Code
  */
 static int control_legacy_daemon_state(struct mbox_context *context,
-					  struct mbox_dbus_msg *req,
+					  struct mbox_dbus_msg *req __attribute__((unused)),
 					  struct mbox_dbus_msg *resp)
 {
 	resp->num_args = DAEMON_STATE_NUM_ARGS;
@@ -73,9 +73,10 @@
  * Resp[0]: LPC Bus State Code
  */
 static int control_legacy_lpc_state(struct mbox_context *context,
-				       struct mbox_dbus_msg *req,
+				       struct mbox_dbus_msg *req __attribute__((unused)),
 				       struct mbox_dbus_msg *resp)
 {
+
 	resp->num_args = LPC_STATE_NUM_ARGS;
 	resp->args = calloc(resp->num_args, sizeof(*resp->args));
 	resp->args[0] = control_lpc_state(context);
@@ -92,8 +93,8 @@
  * Resp: NONE
  */
 static int control_legacy_reset(struct mbox_context *context,
-				   struct mbox_dbus_msg *req,
-				   struct mbox_dbus_msg *resp)
+				   struct mbox_dbus_msg *req __attribute__((unused)),
+				   struct mbox_dbus_msg *resp __attribute__((unused)))
 {
 	int rc;
 
@@ -117,8 +118,8 @@
  * Resp: NONE
  */
 static int control_legacy_kill(struct mbox_context *context,
-				  struct mbox_dbus_msg *req,
-				  struct mbox_dbus_msg *resp)
+				  struct mbox_dbus_msg *req __attribute__((unused)),
+				  struct mbox_dbus_msg *resp __attribute__((unused)))
 {
 	return control_kill(context);
 }
@@ -134,8 +135,8 @@
  * Resp: NONE
  */
 static int control_legacy_modified(struct mbox_context *context,
-				      struct mbox_dbus_msg *req,
-				      struct mbox_dbus_msg *resp)
+				      struct mbox_dbus_msg *req __attribute__((unused)),
+				      struct mbox_dbus_msg *resp __attribute__((unused)))
 {
 	return control_modified(context);
 }
@@ -150,8 +151,8 @@
  * Resp: NONE
  */
 static int control_legacy_suspend(struct mbox_context *context,
-				     struct mbox_dbus_msg *req,
-				     struct mbox_dbus_msg *resp)
+				     struct mbox_dbus_msg *req __attribute__((unused)),
+				     struct mbox_dbus_msg *resp __attribute__((unused)))
 {
 	int rc;
 
@@ -173,7 +174,7 @@
  */
 static int control_legacy_resume(struct mbox_context *context,
 				    struct mbox_dbus_msg *req,
-				    struct mbox_dbus_msg *resp)
+				    struct mbox_dbus_msg *resp __attribute__((unused)))
 {
 	int rc;
 
@@ -205,12 +206,13 @@
 };
 
 static int method_cmd(sd_bus_message *m, void *userdata,
-		      sd_bus_error *ret_error)
+		      sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_dbus_msg req = { 0 }, resp = { 0 };
 	struct mbox_context *context;
 	sd_bus_message *n;
-	int rc, i;
+	int rc;
+	size_t i;
 
 	context = (struct mbox_context *) userdata;
 	if (!context) {
@@ -238,7 +240,7 @@
 	}
 	MSG_DBG("DBUS num_args: %u\n", (unsigned) req.num_args);
 	for (i = 0; i < req.num_args; i++) {
-		MSG_DBG("DBUS arg[%d]: %u\n", i, req.args[i]);
+		MSG_DBG("DBUS arg[%zd]: %u\n", i, req.args[i]);
 	}
 
 	/* Handle the command */
@@ -274,7 +276,7 @@
 	MSG_DBG("DBUS response: %u\n", resp.cmd);
 	MSG_DBG("DBUS num_args: %u\n", (unsigned) resp.num_args);
 	for (i = 0; i < resp.num_args; i++) {
-		MSG_DBG("DBUS arg[%d]: %u\n", i, resp.args[i]);
+		MSG_DBG("DBUS arg[%zd]: %u\n", i, resp.args[i]);
 	}
 
 	rc = sd_bus_send(NULL, n, NULL); /* Send response */
diff --git a/file/backend.c b/file/backend.c
index 865a434..d678c9e 100644
--- a/file/backend.c
+++ b/file/backend.c
@@ -35,6 +35,9 @@
 
 #define FILE_ERASE_SIZE (4 * 1024)
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpointer-arith"
+
 struct file_data {
 	int fd;
 };
@@ -281,3 +284,5 @@
 
 	return backend_init(master, &with, (void *)path);
 }
+
+#pragma GCC diagnostic pop
diff --git a/mboxd.c b/mboxd.c
index 059261b..04b2cb6 100644
--- a/mboxd.c
+++ b/mboxd.c
@@ -255,7 +255,8 @@
 			case '\0':
 				break;
 			case 'M':
-				context->backend.flash_size <<= 10;
+				context->backend.flash_size <<= 20;
+				break;
 			case 'K':
 				context->backend.flash_size <<= 10;
 				break;
diff --git a/mtd/backend.c b/mtd/backend.c
index 921c041..da43072 100644
--- a/mtd/backend.c
+++ b/mtd/backend.c
@@ -31,6 +31,9 @@
 #include "mboxd.h"
 #include "mtd/backend.h"
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpointer-arith"
+
 static int mtd_dev_init(struct backend *backend, void *data)
 {
 	const char *path = data;
@@ -121,8 +124,10 @@
 
 /* Flash Functions */
 
-int flash_validate(struct mbox_context *context, uint32_t offset,
-		   uint32_t size, bool ro)
+int flash_validate(struct mbox_context *context __attribute__((unused)),
+		   uint32_t offset __attribute__((unused)),
+		   uint32_t size __attribute__((unused)),
+		   bool ro __attribute__((unused)))
 {
 	/* Default behaviour is all accesses are valid */
 	return 0;
@@ -333,7 +338,7 @@
  * Return:      A value from enum backend_reset_mode, otherwise a negative
  *		error code
  */
-static int mtd_reset(struct backend *backend,
+static int mtd_reset(struct backend *backend __attribute__((unused)),
 		     void *buf __attribute__((unused)),
 		     uint32_t count __attribute__((unused)))
 {
@@ -370,3 +375,5 @@
 
 	return backend_init(master, &with, (void *)path);
 }
+
+#pragma GCC diagnostic pop
diff --git a/protocol.c b/protocol.c
index ab1c332..4efa83a 100644
--- a/protocol.c
+++ b/protocol.c
@@ -14,6 +14,9 @@
 #include "protocol.h"
 #include "windows.h"
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpointer-arith"
+#pragma GCC diagnostic ignored "-Wunused-result"
 
 #define BLOCK_SIZE_SHIFT_V1		12 /* 4K */
 
@@ -368,8 +371,9 @@
 
 static int generic_flush(struct mbox_context *context)
 {
-	int rc, i, offset, count;
+	int rc, offset, count;
 	uint8_t prev;
+	size_t i;
 
 	offset = 0;
 	count = 0;
@@ -617,8 +621,8 @@
 	return 0;
 }
 
-static int protocol_v2_flush(struct mbox_context *context,
-			     struct protocol_flush *io)
+static int protocol_v2_flush(struct mbox_context *context __attribute__((unused)),
+			     struct protocol_flush *io __attribute__((unused)))
 {
 	if (!(context->current && context->current_is_write)) {
 		MSG_ERR("Tried to call flush without open write window\n");
@@ -705,7 +709,7 @@
 	return 0;
 }
 
-void protocol_free(struct mbox_context *context)
+void protocol_free(struct mbox_context *context __attribute__((unused)))
 {
 	return;
 }
@@ -759,3 +763,5 @@
 
 	return 0;
 }
+
+#pragma GCC diagnostic pop
diff --git a/test/close_window_v2.c b/test/close_window_v2.c
index 9b646f6..a077a00 100644
--- a/test/close_window_v2.c
+++ b/test/close_window_v2.c
@@ -105,4 +105,4 @@
 	short_lifetime(ctx);
 
 	return 0;
-};
+}
diff --git a/test/create_oversize_window.c b/test/create_oversize_window.c
index 2c842cb..cae128d 100644
--- a/test/create_oversize_window.c
+++ b/test/create_oversize_window.c
@@ -54,4 +54,4 @@
 	assert(rc == 0);
 
 	return rc;
-};
+}
diff --git a/test/create_read_window_v2.c b/test/create_read_window_v2.c
index 4e8d1d2..5bc11e8 100644
--- a/test/create_read_window_v2.c
+++ b/test/create_read_window_v2.c
@@ -59,4 +59,4 @@
 	assert(rc == 0);
 
 	return rc;
-};
+}
diff --git a/test/create_write_window_v2.c b/test/create_write_window_v2.c
index b0e246e..ac51b41 100644
--- a/test/create_write_window_v2.c
+++ b/test/create_write_window_v2.c
@@ -58,4 +58,4 @@
 	assert(rc == 0);
 
 	return rc;
-};
+}
diff --git a/test/create_zero_size_window.c b/test/create_zero_size_window.c
index 3e936d0..b3e8035 100644
--- a/test/create_zero_size_window.c
+++ b/test/create_zero_size_window.c
@@ -54,4 +54,4 @@
 	assert(rc == 0);
 
 	return rc;
-};
+}
diff --git a/test/flash_erase.c b/test/flash_erase.c
index fe80f3b..127bf8c 100644
--- a/test/flash_erase.c
+++ b/test/flash_erase.c
@@ -41,7 +41,7 @@
 #define MEM_SIZE 3
 #define ERASE_SIZE 1
 
-int ioctl(int fd, unsigned long request, ...)
+int ioctl(int fd __attribute__((unused)), unsigned long request, ...)
 {
 	va_list ap;
 	struct erase_info_user *provided, *alloced;
diff --git a/test/flash_write.c b/test/flash_write.c
index c5f998c..d330981 100644
--- a/test/flash_write.c
+++ b/test/flash_write.c
@@ -37,7 +37,7 @@
 #define MEM_SIZE 3
 #define ERASE_SIZE 1
 
-int ioctl(int fd, unsigned long request, ...)
+int ioctl(int fd __attribute__((unused)), unsigned long request, ...)
 {
 	va_list ap;
 
@@ -59,7 +59,7 @@
 {
 	struct mbox_context _context, *context = &_context;
 	struct backend *backend = &context->backend;
-	char src[MEM_SIZE];
+	uint8_t src[MEM_SIZE];
 	uint8_t *map;
 	int rc;
 
diff --git a/test/get_flash_info_v2.c b/test/get_flash_info_v2.c
index 36ef8ac..ec0adea 100644
--- a/test/get_flash_info_v2.c
+++ b/test/get_flash_info_v2.c
@@ -49,4 +49,4 @@
 	assert(rc == 0);
 
 	return rc;
-};
+}
diff --git a/test/implicit_flush.c b/test/implicit_flush.c
index f186d19..41f27c5 100644
--- a/test/implicit_flush.c
+++ b/test/implicit_flush.c
@@ -148,4 +148,4 @@
 	flush_on_create(ctx);
 
 	return 0;
-};
+}
diff --git a/test/mark_read_dirty.c b/test/mark_read_dirty.c
index 766e3dc..75100af 100644
--- a/test/mark_read_dirty.c
+++ b/test/mark_read_dirty.c
@@ -61,4 +61,4 @@
 	assert(rc == 0);
 
 	return rc;
-};
+}
diff --git a/test/mark_write_dirty_v2.c b/test/mark_write_dirty_v2.c
index 0c929fe..91965a8 100644
--- a/test/mark_write_dirty_v2.c
+++ b/test/mark_write_dirty_v2.c
@@ -63,4 +63,4 @@
 	assert(rc == 0);
 
 	return rc;
-};
+}
diff --git a/test/mark_write_erased_v2.c b/test/mark_write_erased_v2.c
index 95cff4b..4a17138 100644
--- a/test/mark_write_erased_v2.c
+++ b/test/mark_write_erased_v2.c
@@ -88,4 +88,4 @@
 	assert(rc == 0);
 
 	return rc;
-};
+}
diff --git a/test/mbox.c b/test/mbox.c
index c224b84..ebd5071 100644
--- a/test/mbox.c
+++ b/test/mbox.c
@@ -28,7 +28,7 @@
 void dump_buf(const void *buf, size_t len)
 {
 	const uint8_t *buf8 = buf;
-	int i;
+	size_t i;
 
 	for (i = 0; i < len; i += STEP) {
 		int delta;
@@ -38,7 +38,7 @@
 		delta = len - i;
 		max = delta > STEP ? STEP : delta;
 
-		printf("0x%08x:\t", i);
+		printf("0x%08zx:\t", i);
 		for (j = 0; j < max; j++)
 			printf("0x%02x, ", buf8[i + j]);
 
@@ -75,7 +75,7 @@
 	printf("%s:%d: details.st_size: %ld, RESPONSE_OFFSET + len: %ld\n",
 	       __func__, __LINE__, details.st_size, RESPONSE_OFFSET + len);
 	assert(map != MAP_FAILED);
-	assert(details.st_size >= (RESPONSE_OFFSET + len));
+	assert(details.st_size >= (__off_t)(RESPONSE_OFFSET + len));
 
 	rc = memcmp(expected, &map[RESPONSE_OFFSET], len);
 
diff --git a/test/read_window_cycle.c b/test/read_window_cycle.c
index 8220c63..deef2cf 100644
--- a/test/read_window_cycle.c
+++ b/test/read_window_cycle.c
@@ -71,4 +71,4 @@
 	}
 
 	return !(rc == 1);
-};
+}
diff --git a/test/read_window_mark_write_erased.c b/test/read_window_mark_write_erased.c
index 498ac62..f79d993 100644
--- a/test/read_window_mark_write_erased.c
+++ b/test/read_window_mark_write_erased.c
@@ -63,4 +63,4 @@
 	assert(rc == 0);
 
 	return rc;
-};
+}
diff --git a/test/read_window_write_flush.c b/test/read_window_write_flush.c
index 0f1cace..4420976 100644
--- a/test/read_window_write_flush.c
+++ b/test/read_window_write_flush.c
@@ -62,4 +62,4 @@
 	assert(rc == 0);
 
 	return rc;
-};
+}
diff --git a/test/system.c b/test/system.c
index 24fbcdc..babf11d 100644
--- a/test/system.c
+++ b/test/system.c
@@ -11,8 +11,7 @@
 
 #include "linux/aspeed-lpc-ctrl.h"
 
-static struct aspeed_lpc_ctrl_mapping ctrl = {
-};
+static struct aspeed_lpc_ctrl_mapping ctrl = { .size = 0 };
 
 static struct mtd_info_user mtd = {
 	.type = MTD_NORFLASH,
diff --git a/test/tmpf.c b/test/tmpf.c
index 483231b..6832f7c 100644
--- a/test/tmpf.c
+++ b/test/tmpf.c
@@ -30,6 +30,5 @@
 	if (tmpf->fd)
 		close(tmpf->fd);
 
-	if (tmpf->path)
-		unlink(tmpf->path);
+	unlink(tmpf->path);
 }
diff --git a/test/write_flush_v2.c b/test/write_flush_v2.c
index b53550d..898b595 100644
--- a/test/write_flush_v2.c
+++ b/test/write_flush_v2.c
@@ -143,4 +143,4 @@
 	assert(rc == 0);
 
 	return rc;
-};
+}
diff --git a/transport_dbus.c b/transport_dbus.c
index 18cd0d0..0135d58 100644
--- a/transport_dbus.c
+++ b/transport_dbus.c
@@ -71,7 +71,7 @@
 };
 
 static int transport_dbus_reset(sd_bus_message *m, void *userdata,
-				     sd_bus_error *ret_error)
+				sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context = userdata;
 	sd_bus_message *n;
@@ -99,7 +99,7 @@
 }
 
 static int transport_dbus_get_info(sd_bus_message *m, void *userdata,
-					sd_bus_error *ret_error)
+				   sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context = userdata;
 	struct protocol_get_info io;
@@ -154,7 +154,7 @@
 }
 
 static int transport_dbus_get_flash_info(sd_bus_message *m, void *userdata,
-					 sd_bus_error *ret_error)
+					 sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context = userdata;
 	struct protocol_get_flash_info io;
@@ -193,7 +193,7 @@
 static int transport_dbus_create_window(struct mbox_context *context,
 					bool ro,
 					sd_bus_message *m,
-					sd_bus_error *ret_error)
+					sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct protocol_create_window io;
 	sd_bus_message *n;
@@ -253,7 +253,7 @@
 }
 
 static int transport_dbus_close_window(sd_bus_message *m, void *userdata,
-				sd_bus_error *ret_error)
+				       sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context = userdata;
 	struct protocol_close io;
@@ -289,7 +289,7 @@
 }
 
 static int transport_dbus_mark_dirty(sd_bus_message *m, void *userdata,
-				     sd_bus_error *ret_error)
+				     sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context = userdata;
 	struct protocol_mark_dirty io;
@@ -324,7 +324,7 @@
 }
 
 static int transport_dbus_write_flush(sd_bus_message *m, void *userdata,
-				      sd_bus_error *ret_error)
+				      sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context = userdata;
 	sd_bus_message *n;
@@ -352,7 +352,7 @@
 }
 
 static int transport_dbus_ack(sd_bus_message *m, void *userdata,
-			      sd_bus_error *ret_error)
+			      sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context = userdata;
 	struct protocol_ack io;
@@ -387,7 +387,7 @@
 }
 
 static int transport_dbus_erase(sd_bus_message *m, void *userdata,
-				sd_bus_error *ret_error)
+				sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context = userdata;
 	struct protocol_erase io;
@@ -421,13 +421,13 @@
 	return rc;
 }
 
-static int transport_dbus_get_property(sd_bus *bus,
+static int transport_dbus_get_property(sd_bus *bus __attribute__((unused)),
 				       const char *path,
 				       const char *interface,
 				       const char *property,
 				       sd_bus_message *reply,
 				       void *userdata,
-				       sd_bus_error *ret_error)
+				       sd_bus_error *ret_error __attribute__((unused)))
 {
 	struct mbox_context *context = userdata;
 	bool value;
diff --git a/transport_mbox.c b/transport_mbox.c
index 2759fa5..92d6358 100644
--- a/transport_mbox.c
+++ b/transport_mbox.c
@@ -30,6 +30,9 @@
 #include "windows.h"
 #include "lpc.h"
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpointer-arith"
+
 struct errno_map {
 	int rc;
 	int mbox_errno;
@@ -128,7 +131,8 @@
 }
 
 static int transport_mbox_update_events(struct mbox_context *context,
-					uint8_t events, uint8_t mask)
+					uint8_t events __attribute__((unused)),
+					uint8_t mask)
 {
 	return transport_mbox_flush_events(context, context->bmc_events & mask);
 }
@@ -147,7 +151,8 @@
  * using a virtual pnor.
  */
 static int mbox_handle_reset(struct mbox_context *context,
-			     union mbox_regs *req, struct mbox_msg *resp)
+			     union mbox_regs *req __attribute__((unused)),
+			     struct mbox_msg *resp __attribute__((unused)))
 {
 	return context->protocol->reset(context);
 }
@@ -218,7 +223,8 @@
  * RESP[2:3]: Erase Size (number of blocks)
  */
 static int mbox_handle_flash_info(struct mbox_context *context,
-				  union mbox_regs *req, struct mbox_msg *resp)
+				  union mbox_regs *req __attribute__((unused)),
+				  struct mbox_msg *resp)
 {
 	struct protocol_get_flash_info io;
 	int rc;
@@ -357,7 +363,8 @@
  * ARGS[2:3]: Number to mark dirty (number of blocks)
  */
 static int mbox_handle_dirty_window(struct mbox_context *context,
-				    union mbox_regs *req, struct mbox_msg *resp)
+				    union mbox_regs *req,
+				    struct mbox_msg *resp __attribute__((unused)))
 {
 	struct protocol_mark_dirty io;
 
@@ -386,7 +393,8 @@
  * ARGS[2:3]: Number to erase (number of blocks)
  */
 static int mbox_handle_erase_window(struct mbox_context *context,
-				    union mbox_regs *req, struct mbox_msg *resp)
+				    union mbox_regs *req,
+				    struct mbox_msg *resp __attribute__((unused)))
 {
 	struct protocol_erase io;
 
@@ -419,7 +427,8 @@
  * NONE
  */
 static int mbox_handle_flush_window(struct mbox_context *context,
-				    union mbox_regs *req, struct mbox_msg *resp)
+				    union mbox_regs *req,
+				    struct mbox_msg *resp __attribute__((unused)))
 {
 	struct protocol_flush io = { 0 };
 
@@ -443,7 +452,8 @@
  * ARGS[0]: FLAGS
  */
 static int mbox_handle_close_window(struct mbox_context *context,
-				    union mbox_regs *req, struct mbox_msg *resp)
+				    union mbox_regs *req,
+				    struct mbox_msg *resp __attribute__((unused)))
 {
 	struct protocol_close io = { 0 };
 
@@ -461,7 +471,7 @@
  * ARGS[0]: Bitmap of bits to ack (by clearing)
  */
 static int mbox_handle_ack(struct mbox_context *context, union mbox_regs *req,
-			   struct mbox_msg *resp)
+			   struct mbox_msg *resp __attribute__((unused)))
 {
 	struct protocol_ack io;
 
@@ -581,7 +591,7 @@
 	}
 	MSG_INFO("Writing MBOX response: %u\n", resp.response);
 	len = write(context->fds[MBOX_FD].fd, &resp, sizeof(resp));
-	if (len < sizeof(resp)) {
+	if (len < (ssize_t)sizeof(resp)) {
 		MSG_ERR("Didn't write the full response\n");
 		rc = -errno;
 	}
@@ -610,7 +620,7 @@
 	if (rc < 0) {
 		MSG_ERR("Couldn't read: %s\n", strerror(errno));
 		return -errno;
-	} else if (rc < sizeof(msg->raw)) {
+	} else if (rc < (ssize_t)sizeof(msg->raw)) {
 		MSG_ERR("Short read: %d expecting %zu\n", rc, sizeof(msg->raw));
 		return -1;
 	}
@@ -685,3 +695,5 @@
 {
 	close(context->fds[MBOX_FD].fd);
 }
+
+#pragma GCC diagnostic pop
diff --git a/vpnor/backend.cpp b/vpnor/backend.cpp
index b155cf3..606acee 100644
--- a/vpnor/backend.cpp
+++ b/vpnor/backend.cpp
@@ -519,7 +519,7 @@
 
 struct backend backend_get_vpnor(void)
 {
-    struct backend be = {0};
+    struct backend be = {nullptr, nullptr, 0, 0, 0};
 
     be.ops = &vpnor_ops;
 
diff --git a/vpnor/backend.h b/vpnor/backend.h
index 0102238..949e5c1 100644
--- a/vpnor/backend.h
+++ b/vpnor/backend.h
@@ -3,6 +3,7 @@
 #pragma once
 
 #include <limits.h>
+#include <string.h>
 
 struct mbox_context;
 struct vpnor_partition_table;
diff --git a/vpnor/test/dump_flash.cpp b/vpnor/test/dump_flash.cpp
index 2d5dc5d..1c2e865 100644
--- a/vpnor/test/dump_flash.cpp
+++ b/vpnor/test/dump_flash.cpp
@@ -18,8 +18,8 @@
 
 struct test_context
 {
-    uint8_t seq;
-    struct mbox_context* ctx;
+    uint8_t seq = 0;
+    struct mbox_context* ctx = nullptr;
 };
 
 // Configure the system and the paritions such that we eventually request a
@@ -60,7 +60,7 @@
 {
     namespace test = openpower::virtual_pnor::test;
 
-    struct test_context _tctx = {0}, *tctx = &_tctx;
+    test_context _tctx{}, *tctx = &_tctx;
     size_t len;
     size_t pos;
     int rc;
diff --git a/windows.c b/windows.c
index a62b50c..dfb86db 100644
--- a/windows.c
+++ b/windows.c
@@ -31,6 +31,9 @@
 #include "windows.h"
 #include "backend.h"
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpointer-arith"
+
 /* Initialisation Functions */
 
 /*
@@ -56,7 +59,7 @@
 static int init_window_mem(struct mbox_context *context)
 {
 	void *mem_location = context->mem;
-	int i;
+	size_t i;
 
 	/*
 	 * Carve up the reserved memory region and allocate it to each of the
@@ -67,7 +70,7 @@
 	 */
 	for (i = 0; i < context->windows.num; i++) {
 		uint32_t size = context->windows.window[i].size;
-		MSG_DBG("Window %d @ %p for size 0x%.8x\n", i,
+		MSG_DBG("Window %zd @ %p for size 0x%.8x\n", i,
 			mem_location, size);
 		context->windows.window[i].mem = mem_location;
 		mem_location += size;
@@ -90,7 +93,7 @@
  */
 int windows_init(struct mbox_context *context)
 {
-	int i;
+	size_t i;
 
 	/* Check if window size and number set - otherwise set to default */
 	if (!context->windows.default_size) {
@@ -126,7 +129,7 @@
  */
 void windows_free(struct mbox_context *context)
 {
-	int i;
+	size_t i;
 
 	/* Check window cache has actually been allocated */
 	if (context->windows.window) {
@@ -339,7 +342,7 @@
 void windows_alloc_dirty_bytemap(struct mbox_context *context)
 {
 	struct window_context *cur;
-	int i;
+	size_t i;
 
 	for (i = 0; i < context->windows.num; i++) {
 		cur = &context->windows.window[i];
@@ -427,7 +430,7 @@
 bool windows_reset_all(struct mbox_context *context)
 {
 	bool closed = context->current;
-	int i;
+	size_t i;
 
 	MSG_DBG("Resetting all windows\n");
 
@@ -456,7 +459,7 @@
 {
 	struct window_context *oldest = NULL, *cur;
 	uint32_t min_age = context->windows.max_age + 1;
-	int i;
+	size_t i;
 
 	for (i = 0; i < context->windows.num; i++) {
 		cur = &context->windows.window[i];
@@ -480,7 +483,7 @@
 {
 	struct window_context *largest = NULL, *cur;
 	uint32_t max_size = 0;
-	int i;
+	size_t i;
 
 	for (i = 0; i < context->windows.num; i++) {
 		cur = &context->windows.window[i];
@@ -512,7 +515,7 @@
 				      uint32_t offset, bool exact)
 {
 	struct window_context *cur;
-	int i;
+	size_t i;
 
 	MSG_DBG("Searching for window which contains 0x%.8x %s\n",
 		offset, exact ? "exactly" : "");
@@ -662,3 +665,5 @@
 
 	return 0;
 }
+
+#pragma GCC diagnostic pop