I'm using a WDM driver project in VS 2022. In case of the following code snippet:
extern "C" NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject,
PUNICODE_STRING RegistryPath)
{
DbgPrint("v=%s", 123);
return STATUS_SUCCESS;
}
The DbgPrint has an incorrect %s specifier, which will cause that driver to crash.
The VS editor can see it and shows me an underlined warning C6067:
But when I compile it, that warning is not shown and the project compiles successfully, even though the settings for my project are set to "Level4 (/W4)".
Any idea how to enable that warning C6067 during compilation?

The usual MSVC compiler warnings are
C4xxxandC5xxx. Warnings with other number format are Code Analysis warnings.The
/analyzeoption enables code analysis, which makes the compiler deliberately analyze code semantic for red flags. It has lot more warnings. Some are implemented by the compiler itself, some are available via plugins (like C++ Code Guidelines).There's an option
/analyze:onlyto run with code analysis, but without compilation. This makes sense for larger programs, as code analysis is way slower than the usual compilation, so you compile without/analyzeat all, and have a scheduled run of/analyze:onlyon a build server.To control large number of various Code Analysis warnings in a more convenient way than pragma or compiler switches, there are
.rulesetfiles. They are in%VSINSTALLDIR%\Team Tools\Static Analysis Tools\Rule Sets. They can be edited via IDE, or as XML files, so that you can create your own.rulesetfile, based on an existing one, and suppress any warnings.For example if you run the compiler with
/analyze:onlyon the following program, which does not only try to format an integer as a string, but also tries to obtain that integer by indirection of a null pointer:You'll have the following output:
If you create the following
only_format_string.rulesetfile:And run the conpiler with
/analyze:only /analyze:ruleset only_format_string.ruleset, you'll have only C6067, but not C6011.