From: Hallvard Furuseth Date: Tue, 23 Nov 2010 12:12:54 +0000 (+0000) Subject: ITS#6723: Handle EOF in test programs X-Git-Tag: MIGRATION_CVS2GIT~400 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7c29e2c7c5232a36654b742a5994f3431f6d6de3;p=openldap ITS#6723: Handle EOF in test programs --- diff --git a/libraries/libldap/dntest.c b/libraries/libldap/dntest.c index 0ee80283b0..82e97cc608 100644 --- a/libraries/libldap/dntest.c +++ b/libraries/libldap/dntest.c @@ -81,11 +81,9 @@ main( int argc, char *argv[] ) } if ( strcmp( argv[ 1 ], "-" ) == 0 ) { - size_t len; - - fgets( buf, sizeof( buf ), stdin ); - len = strlen( buf ); - if ( len > 0 && buf[ --len ] == '\n' ) { + size_t len = fgets( buf, sizeof( buf ), stdin ) ? strlen( buf ) : 0; + + if ( len == 0 || buf[ --len ] == '\n' ) { buf[ len ] = '\0'; } strin = buf; @@ -296,4 +294,3 @@ main( int argc, char *argv[] ) return( 0 ); } - diff --git a/tests/progs/slapd-tester.c b/tests/progs/slapd-tester.c index 1e75499568..5e7e49b7df 100644 --- a/tests/progs/slapd-tester.c +++ b/tests/progs/slapd-tester.c @@ -990,7 +990,8 @@ get_search_filters( char *filename, char *filters[], char *attrs[], char *bases[ } else { bases[filter] = ArgDup( line ); } - fgets( line, BUFSIZ, fp ); + if ( fgets( line, BUFSIZ, fp ) == NULL ) + *line = '\0'; if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' ))) *nl = '\0';