We really only allow 0x7fffffff maximum characters, so we now mask out
everything above (not even in an intelligent way). Now accepts zero bufferSize and NULL buffer - although it should probably not catch the latter... git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5408 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -80,9 +80,9 @@ do_div(uint64 *_number, uint32 base)
|
|||||||
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
put_padding(char **_buffer, size_t *_bytesLeft, int32 count)
|
put_padding(char **_buffer, int32 *_bytesLeft, int32 count)
|
||||||
{
|
{
|
||||||
int32 left = (int32)*_bytesLeft;
|
int32 left = *_bytesLeft;
|
||||||
char *string = *_buffer;
|
char *string = *_buffer;
|
||||||
int32 written;
|
int32 written;
|
||||||
bool allWritten;
|
bool allWritten;
|
||||||
@@ -104,16 +104,16 @@ put_padding(char **_buffer, size_t *_bytesLeft, int32 count)
|
|||||||
*string++ = ' ';
|
*string++ = ' ';
|
||||||
|
|
||||||
*_buffer = string;
|
*_buffer = string;
|
||||||
*_bytesLeft = (size_t)(left - written);
|
*_bytesLeft = left - written;
|
||||||
|
|
||||||
return allWritten;
|
return allWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
put_string(char **_buffer, size_t *_bytesLeft, const char *source, size_t length)
|
put_string(char **_buffer, int32 *_bytesLeft, const char *source, int32 length)
|
||||||
{
|
{
|
||||||
size_t left = *_bytesLeft;
|
int32 left = *_bytesLeft;
|
||||||
char *target = *_buffer;
|
char *target = *_buffer;
|
||||||
bool allWritten;
|
bool allWritten;
|
||||||
|
|
||||||
@@ -145,9 +145,9 @@ put_string(char **_buffer, size_t *_bytesLeft, const char *source, size_t length
|
|||||||
|
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
put_character(char **_buffer, size_t *_bytesLeft, char c)
|
put_character(char **_buffer, int32 *_bytesLeft, char c)
|
||||||
{
|
{
|
||||||
size_t left = *_bytesLeft;
|
int32 left = *_bytesLeft;
|
||||||
char *string = *_buffer;
|
char *string = *_buffer;
|
||||||
|
|
||||||
if (left > 0) {
|
if (left > 0) {
|
||||||
@@ -237,8 +237,9 @@ number(char *str, long long num, unsigned base, int size, int precision, int typ
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
vsnprintf(char *buffer, size_t bytesLeft, const char *format, va_list args)
|
vsnprintf(char *buffer, size_t bufferSize, const char *format, va_list args)
|
||||||
{
|
{
|
||||||
|
int32 bytesLeft;
|
||||||
uint64 num;
|
uint64 num;
|
||||||
int base;
|
int base;
|
||||||
char *string;
|
char *string;
|
||||||
@@ -248,8 +249,12 @@ vsnprintf(char *buffer, size_t bytesLeft, const char *format, va_list args)
|
|||||||
/* min. # of digits for integers; max number of chars for from string */
|
/* min. # of digits for integers; max number of chars for from string */
|
||||||
int qualifier; /* 'h', 'l', or 'L' for integer fields */
|
int qualifier; /* 'h', 'l', or 'L' for integer fields */
|
||||||
|
|
||||||
bytesLeft--;
|
if (buffer == NULL || bufferSize == 0)
|
||||||
// make space for the terminating '\0' byte
|
return 0;
|
||||||
|
|
||||||
|
bytesLeft = ((int32)bufferSize - 1) & 0x7fffffff;
|
||||||
|
// make space for the terminating '\0' byte, and we
|
||||||
|
// only allow 2G characters :)
|
||||||
|
|
||||||
for (string = buffer; format[0] && bytesLeft > 0; format++) {
|
for (string = buffer; format[0] && bytesLeft > 0; format++) {
|
||||||
if (format[0] != '%') {
|
if (format[0] != '%') {
|
||||||
|
|||||||
Reference in New Issue
Block a user