summaryrefslogtreecommitdiffstats
path: root/tools/build/cklength.c
diff options
context:
space:
mode:
authorJosh Oguin <josh.oguin@oarcorp.com>2014-11-25 15:55:49 -0600
committerJoel Sherrill <joel.sherrill@oarcorp.com>2014-11-26 07:52:00 -0600
commitb1643030121f5ea336670cc9474f4a4a0b2a21eb (patch)
tree83aeb67ca0c18875345814bcef9dba4304fe839f /tools/build/cklength.c
parentd4ec0a2d75dc9fd1506fe5e38b20e55ba17a1819 (diff)
downloadrtems-b1643030121f5ea336670cc9474f4a4a0b2a21eb.tar.bz2
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.
Diffstat (limited to 'tools/build/cklength.c')
-rw-r--r--tools/build/cklength.c28
1 files changed, 11 insertions, 17 deletions
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;