Menu

KeyError issue in MISRA add-on

2020-06-18
2020-11-18
  • Nicky Larson

    Nicky Larson - 2020-06-18

    I ran into some issues with the MISRA addon: after generating the dump file, running the MISRA addon terminates on a fault (error trace below).

    This seems similar to https://sourceforge.net/p/cppcheck/discussion/general/thread/f7e5153341/ and adding a if statement at the faulty line in the cppcheckdata Python module seems to fix the problem.

    I am attaching a small C++14 header file (test.h) that reproduces the issue using CppCheck version 2.1 (macOS 10.15.5, installed via homebrew).

    Error trace:

    Checking test.h.dump...
    Traceback (most recent call last):
      File "/usr/local/homebrew/Cellar/cppcheck/2.1/share/cppcheck/addons/misra.py", line 3135, in <module>
        main()
      File "/usr/local/homebrew/Cellar/cppcheck/2.1/share/cppcheck/addons/misra.py", line 3076, in main
        checker.parseDump(item)
      File "/usr/local/homebrew/Cellar/cppcheck/2.1/share/cppcheck/addons/misra.py", line 2887, in parseDump
        for cfgNumber, cfg in enumerate(data.iterconfigurations()):
      File "/usr/local/homebrew/Cellar/cppcheck/2.1/share/cppcheck/addons/cppcheckdata.py", line 905, in iterconfigurations
        cfg.setIdMap(cfg_arguments)
      File "/usr/local/homebrew/Cellar/cppcheck/2.1/share/cppcheck/addons/cppcheckdata.py", line 713, in setIdMap
        self.set_id_map(functions_arguments)
      File "/usr/local/homebrew/Cellar/cppcheck/2.1/share/cppcheck/addons/cppcheckdata.py", line 698, in set_id_map
        token.setId(IdMap)
      File "/usr/local/homebrew/Cellar/cppcheck/2.1/share/cppcheck/addons/cppcheckdata.py", line 292, in setId
        self.typeScope = IdMap[self.typeScopeId]
    KeyError: '0x0'
    
     
  • Georgiy Komarov

    Georgiy Komarov - 2020-06-18

    Hello,

    Thanks for reporting this. I can confirm this issue with the latest version on Linux. It seems that problem is related with Cppcheck internals, not with MISRA addon. I got the following error when running this command using Cppcheck built from sources:

    $CPPCHECK/bin/cppcheck --dump addons/test/misra/test-b591be6417.h
    
    Checking addons/test/misra/test-b591be6417.h ...
    cppcheck: /home/jubnzv/Dev/cppcheck/_latest/cppcheck-latest/lib/templatesimplifier.cpp:1438: int TemplateSimplifier::getTemplateNamePosition(const Token*): Assertion `tok && tok->str() == ">"' failed.
    zsh: abort      $CPPCHECK/bin/cppcheck --dump addons/test/misra/test-b591be6417.h
    

    So I suppose that in your case Cppcheck can't generate correct dump file, what caused crash in XML parser in cppcheckdata.py.

     
    • Nicky Larson

      Nicky Larson - 2020-06-18

      Yes sorry for the misleading title of the topic (seems I cannot update it).

      I agree that this seems to point to an issue in the dump generation.

      I initially thought the typename = std::enable_if_t... bits was causing the issue but even without it the dump file does not seem proper.

       
    • Nicky Larson

      Nicky Larson - 2020-06-18

      Not sure if this will be useful to further diagnose but removing the using type = T line in the test file seems to fix the issue.

       
  • David Ledger

    David Ledger - 2020-11-18
     

    Last edit: David Ledger 2020-11-18
    • Georgiy Komarov

      Georgiy Komarov - 2020-11-18

      Hi, David,

      Could you attach a minimal example demonstrating this issue, please?

       

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.