(libT) fix a tr_buildPath() bug reported by pea_

This commit is contained in:
Charles Kerr
2008-10-30 19:47:00 +00:00
parent e04ea4062d
commit e7461eb684
2 changed files with 26 additions and 4 deletions

View File

@@ -615,7 +615,7 @@ tr_buildPath( const char *first_element, ... )
bufLen += strlen( element ) + 1;
element = (const char*) va_arg( vl, const char* );
}
pch = buf = tr_new0( char, bufLen );
pch = buf = tr_new( char, bufLen );
va_end( vl );
/* pass 2: build the string piece by piece */
@@ -623,16 +623,19 @@ tr_buildPath( const char *first_element, ... )
element = first_element;
while( element ) {
const size_t elementLen = strlen( element );
if( pch != buf )
*pch++ = TR_PATH_DELIMITER;
memcpy( pch, element, elementLen );
pch += elementLen;
*pch++ = TR_PATH_DELIMITER;
element = (const char*) va_arg( vl, const char* );
}
va_end( vl );
/* sanity checks & return */
/* terminate the string. if nonempty, eat the unwanted trailing slash */
if( pch != buf )
--pch;
*pch++ = '\0';
/* sanity checks & return */
assert( pch - buf == (off_t)bufLen );
return buf;
}