Upon code review/clang-tidy runs, I came across a function with a signature like this:
void appendFoo(const char * fmt, va_list& rVaList);
I have never seen this before.
Afaik, you can pass va_list
by value (and maybe by pointer?).
This brings me to my first question: Is passing va_list
by reference legal and does it work as expected?
Anyway, appendFoo()
calls vsprintf()
in its definition and clang-tidy gave the following warning: Function 'vsprintf' is called with an uninitialized va_list argument [clang-analyzer-valist.Uninitialized]
. The definition of appendFoo()
look basically like this:
void appendFoo(const char * fmt, va_list& rVaList) {
// retracted: allocate buffer
vsprintf(buffer, fmt, rVaList);
// errorhandling
// de-allocate buffer
}
(Yes, the return value of vsprintf
is ignored and errors are "handled" another way. I'm fixing it ...)
In particular, no va_copy
, va_start
, etc. are called.
Removing the reference and passing va_list
by value, i.e. changing the signature to void appendFoo(const char * fmt, va_list rVaList);
, eliminates the clang-tidy warning.
This brings me to my second question: Is the warning produced by clang-tidy if va_list
is passed by reference a false-positive or is there is actually a problem in passing va_list
as reference?
PS: This question is not a duplicate of varargs(va_list va_start) doesn't work with pass-by-reference parameter. The OP of that question passes an argument by reference to a function taking a va_list. I'm asking about va_list itself being passed as a reference. Oh, well.