From b1643030121f5ea336670cc9474f4a4a0b2a21eb Mon Sep 17 00:00:00 2001 From: Josh Oguin Date: Tue, 25 Nov 2014 15:55:49 -0600 Subject: tools/build/*.c: Clean up issues reported by CodeSonar This code is built without warnings and ignored by Coverity Scan. CodeSonar found a wide range of issues including buffer overruns, buffer underruns, questionable type conversions, leaks, etc. This set of patches addresses all reported issues. --- tools/build/cklength.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'tools/build/cklength.c') diff --git a/tools/build/cklength.c b/tools/build/cklength.c index 47675ce998..fd6ed264cb 100644 --- a/tools/build/cklength.c +++ b/tools/build/cklength.c @@ -125,8 +125,7 @@ int main( opterr = 0; /* we'll report all errors */ while ((c = getopt(argc, argv, GETOPTARGS)) != EOF) - switch (c) - { + switch (c) { case 'l': /* line length */ line_length = atoi( optarg ); if ( line_length < 0 || line_length > BUFFER_SIZE ) @@ -150,8 +149,7 @@ int main( showusage = TRUE; } - if (showusage) - { + if (showusage) { (void) fprintf(stderr, "%s", USAGE); exit(1); } @@ -160,9 +158,10 @@ int main( * traverse and process the arguments */ - for ( ; argv[optind]; optind++) + for ( ; optind < argc; optind++) { if (Failed(process(argv[optind]))) rc = FAILURE; + } return rc; } @@ -268,15 +267,11 @@ error(int error_flag, ...) (void) fflush(stderr); - if (error_flag & (ERR_FATAL | ERR_ABORT)) - { - if (error_flag & ERR_FATAL) - { + if (error_flag & (ERR_FATAL | ERR_ABORT)) { + if (error_flag & ERR_FATAL) { error(0, "fatal error, exiting"); exit(local_errno ? local_errno : 1); - } - else - { + } else { error(0, "fatal error, aborting"); abort(); } @@ -291,19 +286,18 @@ getparm(char *s, { long val; - if ( ! strchr("0123456789-", *s)) - { + if ( !strchr("0123456789-", *s) ) { error(ERR_FATAL, "'%s' is not a number", s); - return min; + /* does not return */ } val = strtol(s, (char **) NULL, 0); - if ((val < min) || (val > max)) - { + if ((val < min) || (val > max)) { if (min == max) error(ERR_FATAL, "%s can only be %ld", s, min); else error(ERR_FATAL, "%s must be between %ld and %ld", msg, min, max); + /* does not return */ } return val; -- cgit v1.2.3