mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-24 00:50:37 +08:00
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:
parent
75e26f0f94
commit
0b722864c0
13
util.c
13
util.c
|
@ -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 );
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user