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:
parent
2fc40f4b1c
commit
9769e07fa9
2 changed files with 7 additions and 3 deletions
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue