From 21cdcdb07c5b141471993f212809813cf9829d72 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 30 Sep 2017 10:16:21 -0700 Subject: [PATCH] Fix compilation warnings on all Debian architectures. (#3007) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit stbuf.st_size is of type off_t, which the standard defines as “extended signed integral type”¹, and for which there is no correct printf format string. Hence, we need to cast it into a hopefully-large-enough type (ugh) and use the corresponding format string. In our case, int64_t should do it, as config files really shouldn’t be anywhere close to those numbers. ① http://pubs.opengroup.org/onlinepubs/007908799/xsh/systypes.h.html --- include/all.h | 1 + src/config_parser.c | 4 +++- src/util.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/all.h b/include/all.h index c26835b9..ecc875d0 100644 --- a/include/all.h +++ b/include/all.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include diff --git a/src/config_parser.c b/src/config_parser.c index 9d8369c8..4e66c911 100644 --- a/src/config_parser.c +++ b/src/config_parser.c @@ -902,7 +902,9 @@ bool parse_file(const char *f, bool use_nagbar) { FREE(current_config); current_config = scalloc(stbuf.st_size + 1, 1); - fread(current_config, 1, stbuf.st_size, fstr); + if ((ssize_t)fread(current_config, 1, stbuf.st_size, fstr) != stbuf.st_size) { + die("Could not fread: %s\n", strerror(errno)); + } rewind(fstr); bool invalid_sets = false; diff --git a/src/util.c b/src/util.c index ba0969c7..dc3444f7 100644 --- a/src/util.c +++ b/src/util.c @@ -500,7 +500,7 @@ ssize_t slurp(const char *path, char **buf) { size_t n = fread(*buf, 1, stbuf.st_size, f); fclose(f); if ((ssize_t)n != stbuf.st_size) { - ELOG("File \"%s\" could not be read entirely: got %zd, want %zd\n", path, n, stbuf.st_size); + ELOG("File \"%s\" could not be read entirely: got %zd, want %" PRIi64 "\n", path, n, (int64_t)stbuf.st_size); free(*buf); *buf = NULL; return -1; -- 2.39.5