views:

36

answers:

1

Hello,

while doing some static code analysis I've found a weird one. On a call like this one:

if(!AfxWinInit(moduleHandle,NULL,::GetCommandLine(),0)

I get the warning C6309 at the second parameter (C6309: argument 2 is null: it does not adhere to function specification of AfxWinInit)

Docs say that for Win32 applications the second parameter must be NULL so the questions is:

a) What's wrong, my code, the AfxWinInit declaration or the static code analysis?

Thanks in advance!

+3  A: 
    friend BOOL AFXAPI AfxWinInit(_In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance,
            _In_z_ LPTSTR lpCmdLine, _In_ int nCmdShow);

That looks wrong to me, the 2nd argument should have been annotated as _In_opt_. From the SAL Annotations documentation:

Optional Option
Describes if the buffer itself is optional. These annotations can be applied to values in the Parameters layer, Return Value layer, or Pre / Post layer.

  • (none) The pointer to the buffer must not be NULL.
  • opt_ The pointer to the buffer might be NULL. It will be checked before being dereferenced.
Hans Passant