Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does clang-tidy say vsnprintf has an uninitialized va_list argument?

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.

like image 407
Joshua Nelson Avatar asked Nov 02 '19 16:11

Joshua Nelson


1 Answers

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.

like image 194
S.S. Anne Avatar answered Nov 08 '22 23:11

S.S. Anne