diff options
author | Josh Oguin <josh.oguin@oarcorp.com> | 2014-11-25 15:55:49 -0600 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@oarcorp.com> | 2014-11-26 07:52:00 -0600 |
commit | b1643030121f5ea336670cc9474f4a4a0b2a21eb (patch) | |
tree | 83aeb67ca0c18875345814bcef9dba4304fe839f /tools/build/eolstrip.c | |
parent | monitor/mon-prmisc.c: Use puts() not fprintf() (diff) | |
download | rtems-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/eolstrip.c')
-rw-r--r-- | tools/build/eolstrip.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/build/eolstrip.c b/tools/build/eolstrip.c index 859f1742c1..e93b45e906 100644 --- a/tools/build/eolstrip.c +++ b/tools/build/eolstrip.c @@ -189,13 +189,14 @@ process(char *arg) /* * Don't count the carriage return. */ - - length = strlen( buffer ) - 1; + length = 0; + if ( *buffer != '\0' ) + length = strnlen( buffer, BUFFER_SIZE ) - 1; if ( buffer[ length ] != '\n' ) error(ERR_ERRNO|ERR_FATAL, "Line %d too long in %s\n", line_number, arg); - while ( isspace( (unsigned char) buffer[ length ] ) ) + while ( length && isspace( (unsigned char) buffer[ length ] ) ) buffer[ length-- ] = '\0'; if ( test_only ) { @@ -208,8 +209,11 @@ process(char *arg) fclose( in ); if ( !test_only ) { - fclose( out ); - rename( outname, arg ); + if (out) fclose( out ); + rc = rename( outname, arg ); + if ( rc != 0 ) { + fprintf( stderr, "Unable to rename %s to %s\n", outname, arg ); + } } return rc; } |