If the format buffer shall not be further increased in size, the
length value mistakenly takes the terminating nul byte into account.
This is in contrast to a successful vsnprintf call.
Also use the correct string length if fallback to stack buffer is
required.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
else if (fmtbuff_length < 1000000)
fmtbuff_length += fmtbuff_length / 4;
else {
- length = fmtbuff_length;
- fmtbuff_heap[length-1] = '\0';
+ fmtbuff[fmtbuff_length - 1] = '\0';
+ length = (int)strlen(fmtbuff);
break;
}
free(fmtbuff_heap);
} else {
/* Leave fmtbuff pointing to the truncated
* string in fmtbuff_stack. */
+ fmtbuff_stack[sizeof(fmtbuff_stack) - 1] = '\0';
fmtbuff = fmtbuff_stack;
- length = sizeof(fmtbuff_stack) - 1;
+ length = (int)strlen(fmtbuff);
break;
}
}