Is there a way we can disable a warning on a specific line that is generatedby CodeSonar

1k Views Asked by At

We are using a third party library dlt for Logging purpose and codeSonar shows warnings in the specific logs for eg:- INFO_LOG(dltContext,"This is my log"); Warning text : Inappropriate Assignment Type This assignment to a parameter is to a location of a different essential type category. The location has essential type signed/int (32 bits) and the value has essential type character/char (8 bits). Violation of MISRA C:2012 10.3: The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category.

Therefore need a way to disable warnings at line level using keywords. CodeSonar shows Inappropriate assignment type in this line and it has no impact to the functioning of the code. Got a similar post but it did not help out:- How to disable a CodeSonar warning in C++

The above states using:- WARNING_FILTER += line_contents:"NOLINT" in the project.conf file, i tried but it did not work.

Kindly share your views on the same if anybody has tried it. Env: x86/c++ 11

1

There are 1 best solutions below

0
On

You can discard a warning in a line of code using the conf parameter WARNING_FILTER, as you tried before, like this:

The syntax is: WARNING_FILTER += <action> <rule> [<rule> ...]

Discard all warnings occurring in file main.c on line 11. (Note: If there are two or more s in a pattern, the pattern will be applied to warnings that match ALL of the rules.)

WARNING_FILTER += discard file=main.c line=11

Discard all warnings occurring on a source line that contains the text "do not issue a warning here" (presumably in a comment).

WARNING_FILTER += discard line_contents:"do not issue a warning here"

The parameter you tried before will only work if the line of code in your project contains "NOLINT".

You can read more about how the WARNING_FILTER parameter is used in the CodeSonar manual, accessible from your CodeSonar hub by click on the link "Manual" in the top right menu on all pages of the hub, by searching for "warning_filter". The first result should be "Compiler-Independent Configuration File Parameters", search this page for "Allows warnings to be modified before they are submitted to the hub, or discarded entirely without being submitted.".

If you want to deal with the warnings on a case by case basis you can set the warning finding to "Don't Care". Once set, the warning will not show up unless you use the visible warnings filter "All" in your hub. (more info in the manual by searching for "Visibility Filter selector", and clicking the search result "GUI Reference", then searching in that page for "Visibility Filter selector")

The setting will persist for all future analyses.

You can find more information on changing warnings in the manual by search for "warning report", clicking the search result "GUI: Warning Report", and searching the page for "Change Warning Form".

If you do not want to see warnings for system include files you can use this parameter:

WARNING_FILTER += discard is_sysinclude

(Note: you will need to make sure to set the parameter: SYSTEM_INCLUDE_PATHS, more info in the manual by searching for "system_include_paths", and clicking the search result "Compiler Independent Configuration File Parameters", then searching the page for "Specifies file system paths which contain system include headers.")

The email to contact GrammaTech support directly is located in the manual under contents: "CodeSonar Manual".