Make string handling a bit more solid be making sure sb_printf returns a null terminated string even on failiure.

darcs-hash:20080120022045-75c98-a47aff63ce7278148ccf027d6ee3ff93b35ee350.gz
This commit is contained in:
liljencrantz 2008-01-20 12:20:45 +10:00
parent 75e26f0f94
commit 0b722864c0

13
util.c
View File

@ -1298,14 +1298,19 @@ int sb_vprintf( string_buffer_t *buffer, const wchar_t *format, va_list va_orig
small. In GLIBC, errno seems to be set to EINVAL either way.
Because of this, sb_printf will on failiure try to
increase the buffer size until the free space is larger than
SB_MAX_SIZE, at which point it will conclude that the error
was probably due to a badly formated string option, and
return an error.
increase the buffer size until the free space is
larger than SB_MAX_SIZE, at which point it will
conclude that the error was probably due to a badly
formated string option, and return an error. Make
sure to null terminate string before that, though.
*/
if( buffer->length - buffer->used > SB_MAX_SIZE )
{
b_append( buffer, &tmp, sizeof(wchar_t) );
buffer->used -= sizeof(wchar_t);
break;
}
buffer->buff = realloc( buffer->buff, 2*buffer->length );