Menu

Wrong HTML report when using -i option in cppcheck

2015-08-05
2015-09-01
  • Sonia Barcos

    Sonia Barcos - 2015-08-05

    Hi,

    I work for a middleware company. We would like to integrate Cppcheck into our build system to help preventing errors and issues in our code. Our code is big, and it's distributed in several modules (each module in a different folder). These modules have many dependencies between them.
    When running cppcheck, we want to run it only once over the whole code to give the whole view to the tool. However, some modules are not related to the core ones, and we want to skip those modules from the analysis. Besides, we have implemented APIs for different languages. So for example, we have some modules for C++ that we would like to analyze separately from the C modules.

    We have basically two options: 1) call cppcheck with a list of the modules that we want to analyze, or 2) call cppcheck from the top level folder of the code, and use -i options to ignore all the modules that shouldn't be analyzed.
    Both approaches worked fine up to the point of creating the XML report. The problem appears when calling cppcheck-htmlreport. We observed that no index.html or stats.html were generated. Besides, only some of the results appearing in the XML were translated into HTML reports. For many results, the HTML pages were not generated.
    Any memory problem can be discarded. We already verified this. Besides, the tool doesn't start creating HTML reports from the XML results consecutively and then it stops. Actually, what happens is that the HTML reports go jumping. I mean, the HTML report for error number 1 in the XML is created, then maybe next one is number 5, and so on.

    We called cppcheck-htmlreport with --source-code option pointing to the top level folder of the code. I think the problem may be caused by this. I tried to call cppcheck just from the top level folder, with no -i options, and then the HTML reports were generated without issues. So it looks like the XML created by using -i options cannot be correctly understood by cppcheck-htmlreport.
    Is there a way to provide -i options to cppcheck-htmlreport as well? I think this could solve the problem...

    I have also noticed that the problem only seems to appear when many modules and code is analyzed. When analyzing only a few modules the HTML report was correct, although we still called cppcheck-htmlreport providing the top level folder as source-dir.

    Is this a known issue in cppcheck HTML generator? Is there any way to solve this?
    Any advice is very much appreciated.

    Thanks,
    Sonia

     
  • Daniel Marjamäki

    this is not a known problem as far as I know.

    and I am not sure if anybody is currently maintaining the html-report script.

    I don't understand how the results can "jump" when -i is used. the xml data does not say that some files have been skipped as far as I know. do you see what happens in the xml data?

     
  • Sonia Barcos

    Sonia Barcos - 2015-09-01

    Hi Daniel,

    I was wrong in my previous comment. It looked like the issue only appeared when using -i option. However, I reproduced the wrong behavior running cppcheck freely over the whole code. After noticing this, I continued investigating to find out what was going on.

    cppcheck-htmlreport just stopped at a certain file, but didn't show any errors. After some time I managed to get it to print an error:

    UnicodeEncodeError: 'ascii' codec can't encode character u'\ufffd' in position 20: ordinal not in range(128)

    This error shows that cppcheck-htmlreport is having issues to encode non-ascii characters (>128). Tool is written in Python, which is the one giving this error. See http://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20

    The best option to fix this is probably to use .encode() as proposed in the above link to properly encode the text.

    In my case, I don't need to print the non-ascii characters, since they only appear in some comments at the beginning or end of our code, introduced by CVS. I implemented a very simple solution, just change cppcheck-htmlreport code to use blank spaces instead of >128 characters. I introduced these changes in line 493 (version 1.69):

    variable = highlight(content, lexer, htmlFormatter).decode(options.source_encoding)
    variable = ''.join([i if ord(i) < 128 else '' for i in variable])
    output_file.write(variable)

    So far, it seems to be working fine. I wanted to let you know in case it's useful for other people, or to fix it in future versions :)

    Thanks a lot for your help.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.