Modify malloc_vsnprintf() validation code.
Modify malloc_vsnprintf() validation code to verify that output is identical to vsnprintf() output, even if both outputs are truncated due to buffer exhaustion.
This commit is contained in:
parent
0a0bbf63e5
commit
824d34e5b7
@ -4,6 +4,12 @@
|
|||||||
/* Size of stack-allocated buffer passed to buferror(). */
|
/* Size of stack-allocated buffer passed to buferror(). */
|
||||||
#define BUFERROR_BUF 64
|
#define BUFERROR_BUF 64
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Size of static buffer used by malloc_[v]{,c,t}printf(). This must be large
|
||||||
|
* enough for all possible uses within jemalloc.
|
||||||
|
*/
|
||||||
|
#define MALLOC_PRINTF_BUFSIZE 4096
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define a custom assert() in order to reduce the chances of deadlock during
|
* Define a custom assert() in order to reduce the chances of deadlock during
|
||||||
* assertion failure.
|
* assertion failure.
|
||||||
|
@ -433,7 +433,7 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
|||||||
ret = i;
|
ret = i;
|
||||||
|
|
||||||
if (config_debug) {
|
if (config_debug) {
|
||||||
char buf[ret + 2];
|
char buf[MALLOC_PRINTF_BUFSIZE];
|
||||||
int tret;
|
int tret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -442,7 +442,7 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
|||||||
*/
|
*/
|
||||||
tret = vsnprintf(buf, sizeof(buf), format, tap);
|
tret = vsnprintf(buf, sizeof(buf), format, tap);
|
||||||
assert(tret == ret);
|
assert(tret == ret);
|
||||||
assert(memcmp(str, buf, ret + 1) == 0);
|
assert(strcmp(buf, str) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef APPEND_C
|
#undef APPEND_C
|
||||||
@ -469,8 +469,7 @@ malloc_snprintf(char *str, size_t size, const char *format, ...)
|
|||||||
const char *
|
const char *
|
||||||
malloc_vtprintf(const char *format, va_list ap)
|
malloc_vtprintf(const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
/* buf must be large enough for all possible uses within jemalloc. */
|
static __thread char buf[MALLOC_PRINTF_BUFSIZE];
|
||||||
static __thread char buf[4096];
|
|
||||||
|
|
||||||
malloc_vsnprintf(buf, sizeof(buf), format, ap);
|
malloc_vsnprintf(buf, sizeof(buf), format, ap);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user