From af3a057919f6a13aa1fda8bb5eb0bbf1e859633b Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 14 Jul 2013 08:28:58 +0200 Subject: calib: The call to fscanf can fail and we should check the return value Coverity wants us to check that fscanf has scanned the amount of variables we want to have. Initialize the scan result to 0/0.0f and warn if the scan has failed. Fixes: Coverity CID 1040774, CID 1040773 --- src/osmo-bts-sysmo/calib_file.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/osmo-bts-sysmo/calib_file.c b/src/osmo-bts-sysmo/calib_file.c index 84de31fb..8098da2f 100644 --- a/src/osmo-bts-sysmo/calib_file.c +++ b/src/osmo-bts-sysmo/calib_file.c @@ -120,15 +120,25 @@ static const unsigned int arrsize_by_band[] = { static float read_float(FILE *in) { - float f; - fscanf(in, "%f\n", &f); + int rc; + float f = 0.0f; + + rc = fscanf(in, "%f\n", &f); + if (rc != 1) + LOGP(DL1C, LOGL_ERROR, + "Reading a float from calib data failed.\n"); return f; } static int read_int(FILE *in) { - int i; - fscanf(in, "%d\n", &i); + int rc; + int i = 0; + + rc = fscanf(in, "%d\n", &i); + if (rc != 1) + LOGP(DL1C, LOGL_ERROR, + "Reading an int from calib data failed.\n"); return i; } -- cgit v1.2.3