]> granicus.if.org Git - transmission/commitdiff
(trunk) improvement to r11864
authorJordan Lee <jordan@transmissionbt.com>
Wed, 9 Feb 2011 06:10:01 +0000 (06:10 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Wed, 9 Feb 2011 06:10:01 +0000 (06:10 +0000)
Since the contents of getcwd() are undefined on error, explicitly terminate the buffer string if getcwd() fails.

daemon/remote.c
utils/create.c

index f09c0c0b89b1a5d866d421aafec3fdabc55eb4ed..9db09a40311916694d3182ff45dd08a5dea78fd4 100644 (file)
@@ -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 );
 }
 
index a715218852ceb8120f91f418c16623bd3e941f3b..96dc63e9babce05236e6151870b32dd5b8034176 100644 (file)
@@ -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 );
 }