cola - 2023-08-30

Hi

It seems that the plist output is incorrect since all diagnostics are mapped to file 0, which is clearly not correct.

It can be reproduced using the simple example below:

header.h:

#ifndef HEADER_H
#define HEADER_H

static int aaa, bbb;

#endif // HEADER_H

main.c:

#include "header.h"

int main(void)
{
    return 0;
}
$ cppcheck --enable=all --plist-output=./ --addon=misra --xml .
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
    <cppcheck version="2.11"/>
    <errors>
Checking main.c ...
        <error id="misra-c2012-12.3" severity="style" msg="misra violation (use --rule-texts=&lt;file&gt; to get proper output)" verbose="misra violation (use --rule-texts=&lt;file&gt; to get proper output)" file0="main.c.25342.dump">
            <location file="header.h" line="4" column="15"/>
        </error>
    </errors>
</results>

Cppcheck correctly finds the problem on line 4 in header.h, but in the plist file the error is located on line 4 in file 0, which is the main.c file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>clang_version</key>
<string>cppcheck version 2.11</string>
 <key>files</key>
 <array>
  <string>main.c</string>
  <string>header.h</string>
 </array>
 <key>diagnostics</key>
 <array>
  <dict>
   <key>path</key>
   <array>
    <dict>
     <key>kind</key><string>event</string>
     <key>location</key>
     <dict>
      <key>line</key><integer>4</integer>
      <key>col</key><integer>15</integer>
      <key>file</key><integer>0</integer>
     </dict>
     <key>ranges</key>
     <array>
       <array>
        <dict>
         <key>line</key><integer>4</integer>
         <key>col</key><integer>15</integer>
         <key>file</key><integer>0</integer>
        </dict>
        <dict>
         <key>line</key><integer>4</integer>
         <key>col</key><integer>15</integer>
         <key>file</key><integer>0</integer>
        </dict>
       </array>
     </array>
     <key>depth</key><integer>0</integer>
     <key>extended_message</key>
     <string>misra violation (use --rule-texts=&lt;file&gt; to get proper output)</string>
     <key>message</key>
     <string>misra violation (use --rule-texts=&lt;file&gt; to get proper output)</string>
    </dict>
   </array>
   <key>description</key><string>misra violation (use --rule-texts=&lt;file&gt; to get proper output)</string>
   <key>category</key><string>style</string>
   <key>type</key><string>misra violation (use --rule-texts=&lt;file&gt; to get proper output)</string>
   <key>check_name</key><string>misra-c2012-12.3</string>
   <!-- This hash is experimental and going to change! -->
   <key>issue_hash_content_of_line_in_context</key><string>0</string>
  <key>issue_context_kind</key><string></string>
  <key>issue_context</key><string></string>
  <key>issue_hash_function_offset</key><string></string>
  <key>location</key>
  <dict>
   <key>line</key><integer>4</integer>
   <key>col</key><integer>15</integer>
   <key>file</key><integer>0</integer>
  </dict>
  </dict>
 </array>
</dict>
</plist>