In the following function, I initialize args
, use them in the call to va_start
, and then call va_end
.
The code looks right to me, but clang-tidy gives a warning:
tmp2.c:7:11: error: Function 'vsnprintf' is called with an uninitialized va_list argument [clang-analyzer-valist.Uninitialized,-warnings-as-errors]
len = vsnprintf((void*)0, 0, format, args);
#include<stdarg.h>
#include<stdio.h>
int f(char *format, ...) {
int len;
va_list args;
va_start(args, format);
len = vsnprintf((void*)0, 0, format, args);
va_end(args);
return len;
}
Even more strangely, this only occurs when I lint multiple files at a time, so clang-tidy tmp2.c
does not give a warning, but clang-tidy tmp2.c tmp2.c
does!
Is this a problem with my code or with clang-tidy? I am using LLVM version 7.0.0, but the warning also occurs with 8.0.0.
It's a bug in clang-tidy
. It's most similar to this bug, which you have apparently seen already.
Also, from a note in the comments, you don't have to cast 0
to (void *)
. The cast is already implicit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With