From 9c50a992af6f1152bedd8b12be27c6ebe03cb425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20K=C4=85dzio=C5=82ka?= Date: Thu, 17 Sep 2020 19:56:31 +0200 Subject: [PATCH 1/3] pb12: check the return value of write --- BootROMs/pb12.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/BootROMs/pb12.c b/BootROMs/pb12.c index 3f6d5f8e..3a72fab2 100644 --- a/BootROMs/pb12.c +++ b/BootROMs/pb12.c @@ -4,6 +4,7 @@ #include #include #include +#include void opts(uint8_t byte, uint8_t *options) { @@ -13,6 +14,17 @@ void opts(uint8_t byte, uint8_t *options) *(options++) = byte & (byte >> 1); } +void write_all(int fd, const void *buf, size_t count) { + while (count) { + ssize_t written = write(fd, buf, count); + if (written < 0) { + err(1, "write"); + } + count -= written; + buf += written; + } +} + int main() { static uint8_t source[0x4000]; @@ -76,15 +88,15 @@ int main() if (bits >= 8) { uint8_t outctl = control >> (bits - 8); assert(outctl != 1); - write(STDOUT_FILENO, &outctl, 1); - write(STDOUT_FILENO, literals, literals_size); + write_all(STDOUT_FILENO, &outctl, 1); + write_all(STDOUT_FILENO, literals, literals_size); bits -= 8; control &= (1 << bits) - 1; literals_size = 0; } } uint8_t end_byte = 1; - write(STDOUT_FILENO, &end_byte, 1); + write_all(STDOUT_FILENO, &end_byte, 1); return 0; } From abea3888dbc527ece51ade3ced2485be8c30840e Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 17 Sep 2020 23:18:16 +0300 Subject: [PATCH 2/3] Fix compilation under GCC 9 --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index ca8ac763..df0ba439 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,11 @@ ifeq ($(shell $(CC) -x c -c $(NULL) -o $(NULL) -Werror -Wpartial-availability 2> WARNINGS += -Wpartial-availability endif +# GCC's implementation of this warning has false positives, so we skip it +ifneq ($(shell $(CC) --version 2>&1 | grep "gcc"), ) +WARNINGS += -no-maybe-uninitialized +endif + CFLAGS += $(WARNINGS) CFLAGS += -std=gnu11 -D_GNU_SOURCE -DVERSION="$(VERSION)" -I. -D_USE_MATH_DEFINES From faf91508e22494c49217943c90b13b30fcf699c0 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Thu, 17 Sep 2020 23:25:56 +0300 Subject: [PATCH 3/3] Yes, I *do* mean -Wno-maybe-uninitialized! --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index df0ba439..be522874 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ endif # GCC's implementation of this warning has false positives, so we skip it ifneq ($(shell $(CC) --version 2>&1 | grep "gcc"), ) -WARNINGS += -no-maybe-uninitialized +WARNINGS += -Wno-maybe-uninitialized endif CFLAGS += $(WARNINGS)