clion-cppcheck icon indicating copy to clipboard operation
clion-cppcheck copied to clipboard

display all the available details of a finding

Open firewave opened this issue 3 years ago • 1 comments

#include <string>

static char* f() {
    return std::string().c_str();
}

Running Cppcheck on the command-line will show the following:

input.cpp:4:31: error: Returning object that will be invalid when returning. [returnDanglingLifetime]
    return std::string().c_str();
                              ^
input.cpp:4:31: note: Pointer to container is created here.
    return std::string().c_str();
                              ^
input.cpp:4:31: note: Returning object that will be invalid when returning.
    return std::string().c_str();
                              ^
input.cpp:4:5: error: Dangerous usage of c_str(). The value returned by c_str() is invalid after this call. [stlcstr]
    return std::string().c_str();
    ^
input.cpp:3:0: style: The function 'f' is never used. [unusedFunction]

^

But CLion only shows the first message for returnDanglingLifetime:

image

For some findings this information is not sufficient to actually understand why it is being reported so we should provide these additional details in the IDE.

firewave avatar May 13 '22 11:05 firewave

I have no suggestion on how to fix it since CLion has the same problem with clang-tidy (https://youtrack.jetbrains.com/issue/CPP-19518) and certain compiler warnings (no ticket yet / some of those are shown as separate entries which might not make sense on their own) so there's not something existing to leverage AFAIK.

I do wonder if it is possible to display additional information in the tooltip:

image

firewave avatar May 13 '22 11:05 firewave

It seems that using #treeend in the description you can add additional information. Unfortunately they are not available straight-forward from the XML as they are given as additional location nodes.

firewave avatar Mar 30 '23 16:03 firewave

Preview:

image

The ... indicates there's more information available via the tool-tip:

image

firewave avatar Mar 30 '23 16:03 firewave