2

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

  • IMHO, your first effort should NOT be an attempt to disable any warning. (And is it a typo that your warning is a MISRA C, not C++?) It appears that the char was not auto promoted to an int ... but on some compilers, chars are unsigned ints (not signedi ints). (Action item - this is something to determine about your compiler.) Does MISRA allow you to use static_cast? See C++ 'implicit conversions', and plan to test your compiler. – 2785528 May 11 '20 at 19:42
  • I Understand your point but the input comes from a third party library function which cannot be modified, so there should be a mechanism provided by codeSonar to use a keyword to avoid a line from being included in the static check like // NOLINT etc. It is not a Typo, the CI guys are using MISRA C static checks. – Kartikey Som May 12 '20 at 05:39

1 Answers1

2

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".