From 6b49b17d6effe037241a7d18b796d401eacc5687 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 8 Apr 2019 13:08:57 -0700 Subject: [PATCH] build: handle possible fscanf errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit on gcc (GCC) 7.4.0 devtools/create-gossipstore.c: In function ‘load_scid_file’: devtools/create-gossipstore.c:22:9: error: ignoring return value of ‘fscanf’ ... fscanf(scidfd, "%d\n", &n); ^~~~~~~~~~~~~~~~~~~~~~~~~~ devtools/create-gossipstore.c:24:9: error: ignoring return value of ‘fscanf’ ... fscanf(scidfd, "%s\n", title); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make: *** [: devtools/create-gossipstore.o] Error 1 Signed-off-by: William Casarin --- devtools/create-gossipstore.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/devtools/create-gossipstore.c b/devtools/create-gossipstore.c index 9f826f5b7..5657d6864 100644 --- a/devtools/create-gossipstore.c +++ b/devtools/create-gossipstore.c @@ -18,10 +18,14 @@ struct scidsat * load_scid_file(FILE * scidfd) { - int n; - fscanf(scidfd, "%d\n", &n); + int n, ok; + ok = fscanf(scidfd, "%d\n", &n); + if (ok == EOF) + return NULL; char title[16]; - fscanf(scidfd, "%s\n", title); + ok = fscanf(scidfd, "%s\n", title); + if (ok == EOF) + return NULL; struct scidsat * scids = calloc(n, sizeof(scidsat)); int i = 0; while(fscanf(scidfd, "%s ,%ld\n", scids[i].scid, &scids[i].sat.satoshis) == 2 ) { /* Raw: read from file */