From 35dcef4fd60357dbb60a59b9ad3b3ba3711506c6 Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Tue, 6 Oct 2015 21:33:58 -0300 Subject: [PATCH] Address Coverity Scan errors Signed-off-by: Claudio Matsuoka --- Changelog | 1 + src/options.c | 1 + src/read_config.c | 22 ++++++++++++++-------- src/sound.h | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Changelog b/Changelog index c769d00..47c7c23 100644 --- a/Changelog +++ b/Changelog @@ -3,6 +3,7 @@ Stable versions 4.0.11 (): - Mark surround channels in channel list + - Address errors reported by Coverity Scan 4.0.10 (20141030): - Add AIFF file output driver (by Lorence Lombardo) diff --git a/src/options.c b/src/options.c index a5b14b0..cd6814c 100644 --- a/src/options.c +++ b/src/options.c @@ -327,6 +327,7 @@ void get_options(int argc, char **argv, struct options *options) break; case 'h': usage(argv[0], options); + /* fall through */ default: exit(-1); } diff --git a/src/read_config.c b/src/read_config.c index 5860aac..0494cbb 100644 --- a/src/read_config.c +++ b/src/read_config.c @@ -81,8 +81,9 @@ int read_config(struct options *o) while (!feof(rc)) { memset(line, 0, 256); - fscanf(rc, "%255[^\n]", line); - fgetc(rc); + if (fscanf(rc, "%255[^\n]", line) < 0 || fgetc(rc) < 0) { + break; + } /* Delete comments */ if ((hash = strchr(line, '#'))) @@ -90,8 +91,9 @@ int read_config(struct options *o) delete_spaces(line); - if (!(var = strtok(line, "=\n"))) + if (!(var = strtok(line, "=\n"))) { continue; + } val = strtok(NULL, " \t\n"); @@ -146,7 +148,8 @@ int read_config(struct options *o) } if (!strcmp(var, "instrument_path")) { - strncpy(instrument_path, val, 256); + strncpy(instrument_path, val, 255); + instrument_path[255] = 0; o->ins_path = instrument_path; continue; } @@ -194,8 +197,9 @@ static void parse_modconf(struct options *o, char *confname, unsigned char *md5) while (!feof(rc)) { memset(line, 0, 256); - fscanf(rc, "%255[^\n]", line); - fgetc(rc); + if (fscanf(rc, "%255[^\n]", line) < 0 || fgetc(rc) < 0) { + break; + } /* Delete comments */ if ((hash = strchr(line, '#'))) @@ -210,13 +214,15 @@ static void parse_modconf(struct options *o, char *confname, unsigned char *md5) continue; } - if (!active) + if (!active) { continue; + } delete_spaces(line); - if (!(var = strtok(line, "=\n"))) + if (!(var = strtok(line, "=\n"))) { continue; + } val = strtok(NULL, " \t\n"); diff --git a/src/sound.h b/src/sound.h index 3028e3d..4a03c87 100644 --- a/src/sound.h +++ b/src/sound.h @@ -20,7 +20,7 @@ struct sound_driver { }; #define parm_init(p) { char *token; for (; *(p); (p)++) { \ - char s[80]; strncpy(s, *(p), 80); \ + char s[80]; strncpy(s, *(p), 79); s[79] = 0; \ token = strtok(s, ":="); token = strtok(NULL, ""); #define parm_end() } } #define parm_error() do { \