From: Jordan Lee Date: Wed, 9 Feb 2011 06:10:01 +0000 (+0000) Subject: (trunk) improvement to r11864 X-Git-Tag: 2.30b1~389 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9769e07fa94660f8c971315104271a43ba56b278;p=transmission (trunk) improvement to r11864 Since the contents of getcwd() are undefined on error, explicitly terminate the buffer string if getcwd() fails. --- diff --git a/daemon/remote.c b/daemon/remote.c index f09c0c0b8..9db09a403 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -491,14 +491,16 @@ tr_getcwd( void ) { char * result; char buf[2048]; - *buf = '\0'; #ifdef WIN32 result = _getcwd( buf, sizeof( buf ) ); #else result = getcwd( buf, sizeof( buf ) ); #endif if( result == NULL ) + { fprintf( stderr, "getcwd error: \"%s\"", tr_strerror( errno ) ); + *buf = '\0'; + } return tr_strdup( buf ); } diff --git a/utils/create.c b/utils/create.c index a71521885..96dc63e9b 100644 --- a/utils/create.c +++ b/utils/create.c @@ -80,14 +80,16 @@ tr_getcwd( void ) { char * result; char buf[2048]; - *buf = '\0'; #ifdef WIN32 result = _getcwd( buf, sizeof( buf ) ); #else result = getcwd( buf, sizeof( buf ) ); #endif - if( result == NULL ) + if( result == NULL ) + { fprintf( stderr, "getcwd error: \"%s\"", tr_strerror( errno ) ); + *buf = '\0'; + } return tr_strdup( buf ); }