1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-31 03:12:44 +00:00

(trunk) improvement to r11864

Since the contents of getcwd() are undefined on error, explicitly terminate the buffer string if getcwd() fails.
This commit is contained in:
Jordan Lee 2011-02-09 06:10:01 +00:00
parent 2fc40f4b1c
commit 9769e07fa9
2 changed files with 7 additions and 3 deletions

View 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 );
}

View 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 );
}