mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 01:58:20 +00:00
Replace va_list fmt() overload with vfmt()
Using an overload that takes a va_list argument potentially causes accidental misuse on platforms (e.g. 32-bit) where va_list is implemented as a type that may collide with commonly-used argument types. For example: char* c = copy_string("hi"); fmt("%s", (const char*)c); fmt("%s", c); The first fmt() call correctly goes through fmt(const char*, ...) first, but the second mistakenly goes through fmt(const char*, va_list) first because variadic function overloads have lower priority during overload resolution and va_list on a 32-bit system happens to be defined as a pointer type that can match with "char*" but not "const char*".
This commit is contained in:
parent
8e353aafe5
commit
8fed26824b
5 changed files with 11 additions and 5 deletions
|
@ -817,7 +817,7 @@ const char* fmt_bytes(const char* data, int len)
|
|||
return buf;
|
||||
}
|
||||
|
||||
const char* fmt(const char* format, va_list al)
|
||||
const char* vfmt(const char* format, va_list al)
|
||||
{
|
||||
static char* buf = 0;
|
||||
static unsigned int buf_len = 1024;
|
||||
|
@ -848,7 +848,7 @@ const char* fmt(const char* format, ...)
|
|||
{
|
||||
va_list al;
|
||||
va_start(al, format);
|
||||
auto rval = fmt(format, al);
|
||||
auto rval = vfmt(format, al);
|
||||
va_end(al);
|
||||
return rval;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue