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/eolstrip.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tools/build/eolstrip.c') 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; } -- cgit v1.2.3