nimble-code / Cobra

An interactive (fast) static source code analyzer
139 stars 31 forks source link

Avoid truncating the error message text #52

Closed mjeronimo closed 2 years ago

mjeronimo commented 2 years ago

Currently, when using the json_convert utility to convert from JSON to other output formats, the rule message text is getting truncated at the first space.

For example, the JSON entry like this:

[
  { "type"  :   "(Required)  #include directives in a file shall only be preceded by other pre-processor directives or comments.",
    "message"   :   "lines 17..29",
    "file"  :   "time.c",
    "line"  :   17,
    "cobra" :   "1 1 40"
  }
]

Is getting converted to this SARIF output:

        "rules": [
            {
              "id": "R0",
              "fullDescription": {
                "text": "(Required)"
              },
              "messageStrings": {
                "default": {
                  "text": "lines 69..69"
                }
              }
            },

Where the string "(Required) #include directives in a file shall only be preceded by other pre-processor directives or comments." is getting truncated to "(Required)" in the output.

Signed-off-by: Michael Jeronimo michael.jeronimo@openrobotics.org

nimble-code commented 2 years ago

Looking at the source, the code does deliberately truncate the "type" field at the first space. That seems odd, but I don't remember the reason for doing so. I'll remove this and allow the full text of the "type" field to be carried forward, and if there was some reason for not doing so it no doubt will show up soon enough!

nimble-code commented 2 years ago

I updated the code, but left in a compiler directive in case the change turns out unwarranted later