none
Code Analysis does not work in VS 2010 - Code Analysis Complete — 0 error(s), 0 warning(s)

    Question

  • I'm trying to use Code Analysis in VS2010, but it's not working.

    My sample appl:

    #include "stdafx.h"
    #include <malloc.h>
    
    int getj() {
            return 10;
    }
    
    int a(int *n) {
            int b = *n;
            int c = 1/b;
            return c;
    }
    
    int _tmain(int argc, _TCHAR* argv[]) {
            int *a;
    
            a = (int *)malloc(10*sizeof(int));
            if( a ) {
                    free( a );
                    a[0] = 12;
                    a[getj()] = 12;
            }
    
            return 0;
    }

    To start analysis, I using "Analyze-> Run Code Analysis on ...."

    and logs:

    1>------ Rebuild All started: Project: test1, Configuration: Debug Win32 ------
    1>Build started 2013-07-01 17:45:40.
    1>_PrepareForClean:
    1>  Deleting file "Debug\test1.lastbuildstate".
    1>InitializeBuildStatus:
    1>  Creating "Debug\test1.unsuccessfulbuild" because "AlwaysCreate" was specified.
    1>ClCompile:
    1>  stdafx.cpp
    1>  test1.cpp
    1>Manifest:
    1>  Deleting file "Debug\test1.exe.embed.manifest".
    1>LinkEmbedManifest:
    1>  test1.vcxproj -> D:\test1\Debug\test1.exe
    1>RunCodeAnalysis:
    1>  Running Code Analysis...
    1>  Code Analysis Complete -- 0 error(s), 0 warning(s)
    1>FinalizeBuildStatus:
    1>  Deleting file "Debug\test1.unsuccessfulbuild".
    1>  Touching "Debug\test1.lastbuildstate".
    1>
    1>Build succeeded.
    1>

    1>Time Elapsed 00:00:03.40

    Config:

    On the "Property page", I have turned on:

    -Enabled Code Analysis ob Build (defines....

    -Enabled Code Analysis for C/C++ on Build

    -Supress results from ...

    - and Ruls Set ->AllRules

    Command line options (properties window c++ -> command line):

    /ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Debug\test1.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze /errorReport:queue

    My question is What I'm doing wrong, or how to run code analysis in VS2010 ?

    thanks

    rupcio




    • Edited by rupcio Monday, July 01, 2013 7:21 PM
    Monday, July 01, 2013 4:39 PM

Answers

  • Hello,

    As my personal point of view, your opinion may make sense. It may be code analysis for specific C/C++ file such as the compiled file:test2.cpp and stdafx.cpp once and then for all .Net.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by rupcio Thursday, July 11, 2013 7:21 AM
    Monday, July 08, 2013 3:32 AM

All replies

  • Hello,

    Thank you for your post.

    I tried your code on my VS2010 and get the same result. In the log information, it indicates that Code Analysis run and the result is no error and warning.

    Please see:

    1>RunCodeAnalysis:

    1> Running Code Analysis...

    1>Code Analysis Complete -- 0 error(s), 0 warning(s)

    According to this article: Code Analysis for C/C++ Overview,  during the build process, any warnings generated for the source code appear in the Error List. You can check the Error list. Note that code analysis is used to improve the quality of your application.

    You can refer to this article: Code Analysis Properties for C/C++ to enable code analysis. I think that what you have done is right. And the code analysis has run.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 02, 2013 9:23 AM
  • hi, thanks for your help but ...:)

    my second appl:

    #include "stdafx.h" 
    int _tmain(int argc, _TCHAR* argv[]) 

            static const int m_size = 100; 
        char m_tab[m_size]; 
            for (int i=0; i< m_size; i++) 
                    { 
                            m_tab[i] = m_tab[i+1]; 
                    } 

            int *a = NULL; 
            //a[12] = 2; 
            a = new int[10]; 
            delete a; 
            a[0] = 12; 
            //a[11] = 2; 
            return 0; 

    Code Analysis found warinings:

    1>------ Rebuild All started: Project: test2, Configuration: Debug Win32 ------
    1>Build started 2013-07-02 11:31:37.
    1>_PrepareForClean:
    1>  Deleting file "Debug\test2.lastbuildstate".
    1>InitializeBuildStatus:
    1>  Creating "Debug\test2.unsuccessfulbuild" because "AlwaysCreate" was specified.
    1>ClCompile:
    1>  test2.cpp
    1>  stdafx.cpp
    1>  Running Code Analysis for C/C++...
    1>d:\test2\test2\test2.cpp(12): warning C6201: Index '100' is out of valid index range '0' to '99' for possibly stack allocated buffer 'm_tab'
    1>d:\test2\test2\test2.cpp(18): warning C6283: 'a' is allocated with array new [], but deleted with scalar delete: Lines: 17, 18
    1>  Generating Code...
    1>Manifest:
    1>  Deleting file "Debug\test2.exe.embed.manifest".
    1>LinkEmbedManifest:
    1>  test2.vcxproj -> D:\test2\Debug\test2.exe
    1>RunCodeAnalysis:
    1>  Running Code Analysis...
    1>  Code Analysis Complete -- 0 error(s), 0 warning(s)
    1>FinalizeBuildStatus:
    1>  Deleting file "Debug\test2.unsuccessfulbuild".
    1>  Touching "Debug\test2.lastbuildstate".
    1>
    1>Build succeeded.
    1>
    1>Time Elapsed 00:00:02.86
    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

    Export reports to the external file, by adding to project file :

    <CodeAnalysisApplyLogFileXsl>true</CodeAnalysisApplyLogFileXsl>

    but report file *.CodeAnalysisLog.xml is without warnings, body part is empty.

    How to configure Code Analysis to reports results to the external file ?

    rupico



    • Edited by rupcio Tuesday, July 02, 2013 5:42 PM small changes
    Tuesday, July 02, 2013 9:40 AM
  • Hello,

    I did some search about this issue, it seems that it will only generate an XML file in $(AssemblyName).CodeAnalaysis.xml by default when you use <CodeAnalysisApplyLogFileXsl>true</CodeAnalysisApplyLogFileXsl> in project file manually.

    For more information, please see Jesse’s reply in this thread:

    http://social.msdn.microsoft.com/Forums/en-US/898994f4-8025-465e-823a-15d918d0230a/how-to-generate-report-for-static-code-analysis-

    Even though I specify an external file in <CodeAnalysisLogFileXsl>Path to xsl</CodeAnalysisLogFileXsl>, the code analysis log file still is generated under the solution path.

    If you want to check them in an external file, you can select all the warnings in Error List, copy and paste them into an Excel file.

    For more information, please see: http://stackoverflow.com/questions/16558348/how-to-get-code-analysis-report-in-vs-2012

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 03, 2013 4:06 AM
  • Hi,

    Thanks for answer, 

    Please let me know, if I correct understand:

    1. Code Analysis in Visual Studio 2010 (Ultimate or Premium)- there is no possibility to report warning and errors to the external file ? I can only copy and paste them manually to the external file. 

    And I have additional questions:

    1. In the log file I have two times info about code analysis, why ?

    once:

    1> Running Code Analysis for C/C++...

    second time:

    1>RunCodeAnalysis:
    1>  Running Code Analysis...

    2. Which version of Visual Studio (maybe 2012?) has the the possibility to report warnings and errors to the external file ?

    regards 

    rupcio

    Wednesday, July 03, 2013 5:45 AM
  • Hello,

    Based on the result of searching, as my personal point of view, we can’t report warning and errors to the external file for Code Analysis in VS2010 and VS2012.

    In addition, I can’t get Running Code Analysis for C/C++... line in the Output window in VS2010 and VS2012 Ultimate on my side. Which version of VS2010 do you use? If you try the same project in VS2012 or on another machine with VS2010, will you see it?

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, July 04, 2013 9:35 AM
  • hi

    In my case,  Visual Studio 2012 Professional working fine and generates reports file. 

     I upload it here:

    http://speedy.sh/vhbry/ConsoleApplication1.cpp.nativecodeanalysis.xml

    Output logs:

    1>------ Rebuild All started: Project: ConsoleApplication1, Configuration: Debug Win32 ------

    1>Build started 2013-07-04 12:47:16.

    1>_PrepareForClean:

    1>  Deleting file "Debug\ConsoleApplication1.lastbuildstate".

    1>InitializeBuildStatus:

    1>  Creating "Debug\ConsoleApplication1.unsuccessfulbuild" because "AlwaysCreate" was specified.

    1>ClCompile:

    1>  stdafx.cpp

    1>  ConsoleApplication1.cpp

    1>Link:

    1>  ConsoleApplication1.vcxproj -> D:\temp1\Test1\ConsoleApplication1\Debug\ConsoleApplication1.exe

    consoleapplication1.cpp(13): warning : C6201: Index '100' is out of valid index range '0' to '99' for possibly stack allocated buffer 'm_tab'.

    consoleapplication1.cpp(18): warning : C6279: 'a' is allocated with scalar new, but deleted with array delete [].

    consoleapplication1.cpp(13): warning : C6001: Using uninitialized memory 'm_tab'.

    consoleapplication1.cpp(19): warning : C6001: Using uninitialized memory 'a'.

    1>FinalizeBuildStatus:

    1>  Deleting file "Debug\ConsoleApplication1.unsuccessfulbuild".

    1>  Touching "Debug\ConsoleApplication1.lastbuildstate".

    1>

    1>Build succeeded.

    1>

    1>Time Elapsed 00:00:06.39

    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

    But there are no information  about code analysis. :(  But all warnings are in the Code Analysis window. 

    rupcio


    Thursday, July 04, 2013 10:52 AM
  • Hello,

    I can get the same result when I run Code Analysis in VS2012. I think that it is by design for VS2012 Code Analysis.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, July 05, 2013 2:17 AM
  • hi, 

    Did you know how Code Analysis works in VS2010, I think about duplicated info:

    1. In the log file I have two times info about code analysis, why ?

    once:

    1> Running Code Analysis for C/C++... 

    second time:

    1>RunCodeAnalysis:
    1>  Running Code Analysis...

    I suppose the analysis is divided into two levels. Once for C/C++ - executed by compiler - first log , second one by  integrated in VS2010 FxCop for .Net.

     Do you think it makes sense ?

    rupcio


    • Edited by rupcio Friday, July 05, 2013 6:02 AM misspellings
    Friday, July 05, 2013 6:01 AM
  • Hello,

    As my personal point of view, your opinion may make sense. It may be code analysis for specific C/C++ file such as the compiled file:test2.cpp and stdafx.cpp once and then for all .Net.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by rupcio Thursday, July 11, 2013 7:21 AM
    Monday, July 08, 2013 3:32 AM