Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why _Printf_format_string_ macro doesn't produce any warnings?

In the following snippet the wrong usage of format specifiers inside the MyFormat() call should produce a warning, according to SAL specifications, and if I uncomment the identical call of printf(), I really will receive all these warnings, but my code is compiled silently even with /W4. What am I doing wrong? I'm using MSVC 2017 15.9.7 Community edition.

#include <stdio.h>
#include <stdarg.h>

void MyFormat(_Printf_format_string_ const char *fmt, ...)
{
   va_list va;
   va_start(va, fmt);
   vprintf(fmt, va);
   va_end(va);
}

int main()
{
   MyFormat("blabla %s\n", L"qq");
   // printf("blabla %s\n", L"qq");
   return 0;
}
like image 362
George Hazan Avatar asked Feb 22 '19 11:02

George Hazan


1 Answers

Adding the /analyze flag will cause this to produce a warning. However it is a different (and in my opinion inferior) warning than what you would get from printf. Unfortunately I can't find a way to make a user-defined function to produce that style of warning.

like image 71
David Brown Avatar answered Nov 10 '22 08:11

David Brown