9

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.

Boann
  • 48,794
  • 16
  • 117
  • 146
jyn
  • 463
  • 4
  • 16

1 Answers1

7

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.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76