locked
Code analysis shows warnings in strsafe.h

    Dotaz

  • I enabled Code Analysis for C++ from Visual Studio 2008 Team and I get a lot of warnings in strsafe.h.

    This makes it very difficult to find the warnings that are specific to my source files.  Is there a way for me to disable code analysis  warnings that occur in the Microsoft SDK headers.

     

    I am using the following versions.

      - Visual Studio Team System 2008 trial edition version 9.0.21022.8 RTM.

      - Microsoft Windows Software Development Kit (SDK) for Windows Server 2008 and .NET Framework 3.5  Version 6.1

     

     

    Below is a sample of the warnings code analysis generates.

    1>c:\program files\microsoft sdks\windows\v6.1\include\strsafe.h(729) : warning C6387: 'argument 4' might be '0': this does not adhere to the specification for the function 'StringCopyWorkerA': Lines: 684, 686, 692, 694, 695, 697, 699, 701, 710, 727, 729

    1>c:\program files\microsoft sdks\windows\v6.1\include\strsafe.h(713) : warning C6011: Dereferencing NULL pointer 'pszSrc': Lines: 684, 686, 692, 694, 695, 697, 699, 701, 710, 713

    1>c:\program files\microsoft sdks\windows\v6.1\include\strsafe.h(756) : warning C6011: Dereferencing NULL pointer 'pszDest': Lines: 684, 686, 692, 694, 695, 697, 699, 754, 756

    1>c:\program files\microsoft sdks\windows\v6.1\include\strsafe.h(770) : warning C6387: 'argument 1' might be '0': this does not adhere to the specification for the function 'StringExHandleOtherFlagsA': Lines: 684, 686, 692, 694, 695, 697, 699, 754, 756, 761, 764, 767, 770

     

    Thanks.
    8. dubna 2008 14:34

Odpovědi

  • Brett has the practical answer on suppressing the problem appended.

     

    I will also note that this problem has been sent to the Windows SDK team and they are aware of the problems with strsafe.h not being prefast clean.  We currently believe the header is ok, but that the analysis is being agressive because it can't determine enough information to make sure it's clean.  Nevertheless, we are working on getting the header to not produce warnings.

     

    Joe

    ------------------------------

     

    Forwarded from Brett on our team:

    Hi Balbir,

     

    I apologize for the delay in responding to your question.  The easiest way to disable these warnings is to wrap your #include statements in the following construct:

     

    #include <CodeAnalysis/warnings.h>

    #pragma warning(push)

    #pragma warning(disable: ALL_CODE_ANALYSIS_WARNINGS)

     

    #include <strsafe.h>

    <any other #includes>

     

    #pragma warning(pop)

     

    This should disable Code Analysis on the #included files.  CodeAnalysis/warnings.h contains only the definition of ALL_CODE_ANALYSIS WARNINGS, so it will not introduce any new warnings.

     

    15. dubna 2008 18:32