Since the contents of getcwd() are undefined on error, explicitly terminate the buffer string if getcwd() fails.
{
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 );
}
{
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 );
}