From 9e86fc903eed2e7a19e6b6cf3e84d1387a1a0a6f Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Sun, 22 Oct 2017 08:23:58 +1030 Subject: [PATCH] genann: Fix unused-result warnings for fscanf() Signed-off-by: Andrew Jeffery --- genann.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/genann.c b/genann.c index 9becd71..4571471 100644 --- a/genann.c +++ b/genann.c @@ -30,6 +30,7 @@ #include #include #include +#include #define LOOKUP_SIZE 4096 @@ -122,13 +123,27 @@ genann *genann_init(int inputs, int hidden_layers, int hidden, int outputs) { genann *genann_read(FILE *in) { int inputs, hidden_layers, hidden, outputs; - fscanf(in, "%d %d %d %d", &inputs, &hidden_layers, &hidden, &outputs); + int rc; + + errno = 0; + rc = fscanf(in, "%d %d %d %d", &inputs, &hidden_layers, &hidden, &outputs); + if (rc < 4 || errno != 0) { + perror("fscanf"); + return NULL; + } genann *ann = genann_init(inputs, hidden_layers, hidden, outputs); int i; for (i = 0; i < ann->total_weights; ++i) { - fscanf(in, " %le", ann->weight + i); + errno = 0; + rc = fscanf(in, " %le", ann->weight + i); + if (rc < 1 || errno != 0) { + perror("fscanf"); + genann_free(ann); + + return NULL; + } } return ann;