Menu

The file indexing in `-plist-output` output is sometimes set to 0, because the code reported the error didn't provide info about the indexing

Tal
2024-11-20
2024-12-04
  • Tal

    Tal - 2024-11-20

    The file indexing in -plist-output output (used for formatting results in CodeChecker-friendly way) is sometimes set to 0, because the code reported the error didn't provide info about the indexing.
    For example, I get in the errors of ctunullpointer but inspecting the .plist file you see that the file index is set to 0, which results with CodeChecker not pointing to the right file on the stack call view of it.

    Here is a not-too-ugly patch I used locally (i.e. store in a static variable the input file list, and search for that on error outputting). Anything better that you can suggest?

    diff --git lib/errorlogger.cpp lib/errorlogger.cpp
    index 11616b362fd1..303c92a01a5f 100644
    --- lib/errorlogger.cpp
    +++ lib/errorlogger.cpp
    @@ -28,6 +28,7 @@
     #include "utils.h"
    
     #include <algorithm>
    +#include <iterator>
     #include <array>
     #include <cassert>
     #include <cctype>
    @@ -782,8 +783,12 @@ std::string ErrorLogger::toxml(const std::string &str)
         return xml;
     }
    
    +// A trick to fix empty file Index info in the error messages
    +static std::vector<std::string> activeFileList;
    +
     std::string ErrorLogger::plistHeader(const std::string &version, const std::vector<std::string> &files)
     {
    +    activeFileList = files;
         std::ostringstream ostr;
         ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
              << "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\r\n"
    @@ -803,11 +808,17 @@ std::string ErrorLogger::plistHeader(const std::string &version, const std::vect
    
     static std::string plistLoc(const char indent[], const ErrorMessage::FileLocation &loc)
     {
    +    unsigned int actualFileIndex = loc.fileIndex;
    +    const auto it = std::find(activeFileList.begin(), activeFileList.end(), loc.getfile());
    +    if (it != activeFileList.end()) {
    +        // fix actualFileIndex when it is found
    +        actualFileIndex = std::distance(activeFileList.begin(), it);
    +    }
         std::ostringstream ostr;
         ostr << indent << "<dict>\r\n"
              << indent << ' ' << "<key>line</key><integer>" << loc.line << "</integer>\r\n"
              << indent << ' ' << "<key>col</key><integer>" << loc.column << "</integer>\r\n"
    -         << indent << ' ' << "<key>file</key><integer>" << loc.fileIndex << "</integer>\r\n"
    +         << indent << ' ' << "<key>file</key><integer>" << actualFileIndex << "</integer>\r\n"
              << indent << "</dict>\r\n";
         return ostr.str();
     }
    
     
  • Oliver Stöneberg

    Thanks for your report.

    I need to write some tests for the ctu* checks "soon" and will include this use case. I will file an upstream ticket when I have a failing test case. Quite possible there are some other tests which should be extended as well.

     

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.