bootstrap: Ratchet up compiler strictness

Replace the specific warning flags with -Wall -Wextra and turn on
-Werror.

Covered by -Wall:

* -Wformat
* -Warray-bounds
* -Wimplicit-function-declaration

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Iab21e67026d2453648aa6ebe4c299e1162fc5ebf
diff --git a/astlpc.c b/astlpc.c
index 4014b89..a5a3a82 100644
--- a/astlpc.c
+++ b/astlpc.c
@@ -237,7 +237,8 @@
 		return;
 	}
 
-	if (len > astlpc->binding.pkt_size) {
+	assert(astlpc->binding.pkt_size >= 0);
+	if (len > (uint32_t)astlpc->binding.pkt_size) {
 		mctp_prwarn("invalid RX len 0x%x", len);
 		return;
 	}
diff --git a/bootstrap.sh b/bootstrap.sh
index f154ad9..304aca3 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -14,9 +14,11 @@
 
 case "${BOOTSTRAP_MODE}" in
     dev)
-        FLAGS="-Wformat -Werror=format-security"
-        FLAGS="${FLAGS} -Werror=array-bounds"
-        FLAGS="${FLAGS} -Werror=implicit-function-declaration"
+        FLAGS="-O2 -Wall -Wextra -Wformat-security"
+        FLAGS="${FLAGS} -Wparentheses"
+        FLAGS="${FLAGS} -Wno-type-limits"
+        FLAGS="${FLAGS} -Werror"
+        # FLAGS="${FLAGS} -Wpedantic"
         FLAGS="${FLAGS} -fsanitize=address,leak,undefined"
         FLAGS="${FLAGS} -ggdb"
         ./configure \
diff --git a/core.c b/core.c
index a46a733..95c38aa 100644
--- a/core.c
+++ b/core.c
@@ -67,8 +67,8 @@
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 #endif
 
-static int mctp_message_tx_on_bus(struct mctp *mctp, struct mctp_bus *bus,
-		mctp_eid_t src, mctp_eid_t dest, void *msg, size_t msg_len);
+static int mctp_message_tx_on_bus(struct mctp_bus *bus, mctp_eid_t src,
+				  mctp_eid_t dest, void *msg, size_t msg_len);
 
 struct mctp_pktbuf *mctp_pktbuf_alloc(struct mctp_binding *binding, size_t len)
 {
@@ -240,9 +240,10 @@
 
 void mctp_destroy(struct mctp *mctp)
 {
-	int i;
+	size_t i;
 
 	/* Cleanup message assembly contexts */
+	BUILD_ASSERT(ARRAY_SIZE(mctp->msg_ctxs) < SIZE_MAX);
 	for (i = 0; i < ARRAY_SIZE(mctp->msg_ctxs); i++) {
 		struct mctp_msg_ctx *tmp = &mctp->msg_ctxs[i];
 		if (tmp->buf)
@@ -320,9 +321,8 @@
 		(hdr->command_code <= MCTP_CTRL_CMD_LAST_TRANSPORT));
 }
 
-static bool mctp_ctrl_handle_msg(struct mctp *mctp, struct mctp_bus *bus,
-				 mctp_eid_t src, mctp_eid_t dest, void *buffer,
-				 size_t length)
+static bool mctp_ctrl_handle_msg(struct mctp_bus *bus, mctp_eid_t src,
+				 void *buffer, size_t length)
 {
 	struct mctp_ctrl_msg_hdr *msg_hdr = buffer;
 
@@ -384,8 +384,8 @@
 			 */
 			if (mctp_ctrl_cmd_is_request(msg_hdr)) {
 				bool handled;
-				handled = mctp_ctrl_handle_msg(mctp, bus, src,
-							       dest, buf, len);
+				handled = mctp_ctrl_handle_msg(bus, src, buf,
+							       len);
 				if (handled)
 					return;
 			}
@@ -402,8 +402,7 @@
 			if (dest_bus == bus)
 				continue;
 
-			mctp_message_tx_on_bus(mctp, dest_bus,
-					src, dest, buf, len);
+			mctp_message_tx_on_bus(dest_bus, src, dest, buf, len);
 		}
 
 	}
@@ -551,8 +550,8 @@
 		mctp_send_tx_queue(bus);
 }
 
-static int mctp_message_tx_on_bus(struct mctp *mctp, struct mctp_bus *bus,
-		mctp_eid_t src, mctp_eid_t dest, void *msg, size_t msg_len)
+static int mctp_message_tx_on_bus(struct mctp_bus *bus, mctp_eid_t src,
+				  mctp_eid_t dest, void *msg, size_t msg_len)
 {
 	size_t max_payload_len, payload_len, p;
 	struct mctp_pktbuf *pkt;
@@ -613,5 +612,5 @@
 	struct mctp_bus *bus;
 
 	bus = find_bus_for_eid(mctp, eid);
-	return mctp_message_tx_on_bus(mctp, bus, bus->eid, eid, msg, msg_len);
+	return mctp_message_tx_on_bus(bus, bus->eid, eid, msg, msg_len);
 }
diff --git a/tests/test_astlpc.c b/tests/test_astlpc.c
index c5f9e93..369702e 100644
--- a/tests/test_astlpc.c
+++ b/tests/test_astlpc.c
@@ -122,7 +122,10 @@
 	return 0;
 }
 
-static void rx_message(uint8_t eid, void *data, void *msg, size_t len)
+#define __unused __attribute__((unused))
+
+static void rx_message(uint8_t eid __unused, void *data __unused, void *msg,
+		       size_t len)
 {
 	uint8_t type;
 
diff --git a/tests/test_cmds.c b/tests/test_cmds.c
index 7a05c35..1772734 100644
--- a/tests/test_cmds.c
+++ b/tests/test_cmds.c
@@ -30,8 +30,11 @@
 	};
 };
 
-static void control_message_transport_callback(mctp_eid_t src, void *data,
-					       void *buf, size_t len)
+#define __unused __attribute__((unused))
+
+static void control_message_transport_callback(mctp_eid_t src __unused,
+					       void *data, void *buf,
+					       size_t len __unused)
 {
 	struct callback_data *ctx = data;
 	struct mctp_ctrl_msg_hdr *msg_hdr = buf;
@@ -98,7 +101,7 @@
 	mctp_destroy(endpoint);
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
 	send_transport_control_message();
 
diff --git a/tests/test_serial.c b/tests/test_serial.c
index eef66d0..12d1476 100644
--- a/tests/test_serial.c
+++ b/tests/test_serial.c
@@ -33,7 +33,8 @@
 	ssize_t rc;
 
 	rc = write(ctx->egress, buf, len);
-	assert(rc == len);
+	assert(rc >= 0);
+	assert((size_t)rc == len);
 
 	return rc;
 }
@@ -42,7 +43,10 @@
 
 static bool seen;
 
-static void rx_message(uint8_t eid, void *data, void *msg, size_t len)
+#define __unused __attribute__((unused))
+
+static void rx_message(uint8_t eid __unused, void *data __unused, void *msg,
+		       size_t len)
 {
 	uint8_t type;
 
diff --git a/utils/mctp-demux-daemon.c b/utils/mctp-demux-daemon.c
index b7500b5..fc5d583 100644
--- a/utils/mctp-demux-daemon.c
+++ b/utils/mctp-demux-daemon.c
@@ -6,6 +6,7 @@
 #include <err.h>
 #include <errno.h>
 #include <getopt.h>
+#include <limits.h>
 #include <poll.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -334,7 +335,7 @@
 		goto out_close;
 	}
 
-	if (len > ctx->buf_size) {
+	if ((size_t)len > ctx->buf_size) {
 		void *tmp;
 
 		tmp = realloc(ctx->buf, len);