[C-safe-secure-studygroup] On MISRA C:2012 Rule 2.5

Kostya Serebryany kcc at google.com
Wed Feb 22 00:28:49 UTC 2017


On Mon, Feb 20, 2017 at 2:42 AM, Roberto Bagnara <bagnara at cs.unipr.it>
wrote:

>
> This advisory rule recommends against unused macro definitions
> on the grounds that they impair readability and maintainability
> (like any other sort of unused/unnecessary stuff that may clutter
> the project sources.
>
> The rule is usually not applied to system header files and library
> header files, which tend to contain lots of unused macro definitions
> that are perfectly justified.
>
> Whether to include a similar rule in the standard we are working
> on in this group depends on its objectives (which, to me, at least,
> are less and less clear).  So I prefer to give my answer to questions
> that may be relevant.
>
> Q1: Can violations of the rule directly threat safety and security?
> A1: No: unused macros have no effects on the generated code.
>

Imagine this code in a .c file:
  #define NODEBUG 1  // disable assert
  ...
  #include <assert.h>
  ...

  assert(someScaryStuff());

Here we have a typo in the macro definition (NODEBUG instead of NDEBUG)
and thus NODEBUG is unused, assert() is not disabled and the production
binary has
someScaryStuff().

So, my answer would be 'maybe yes'



>
> Q2: Can violations of the rule indirectly threat safety and security?
> A2: Yes: they have the potential of diminishing the effectiveness
>     of peer review.
>
> Q3: Should an analyzer be able to detect unused macros?
> A3: Yes, as part of its general ability to precisely track the
>     preprocessing translation phase.
>
>
> --
>      Prof. Roberto Bagnara
>
> Applied Formal Methods Laboratory - University of Parma, Italy
> mailto:bagnara at cs.unipr.it
>                               BUGSENG srl - http://bugseng.com
>                               mailto:roberto.bagnara at bugseng.com
>
> _______________________________________________
> C-safe-secure-studygroup mailing list
> C-safe-secure-studygroup at lists.trustable.io
> https://lists.trustable.io/cgi-bin/mailman/listinfo/c-
> safe-secure-studygroup
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.trustable.io/pipermail/c-safe-secure-studygroup/attachments/20170221/decce34f/attachment.html>


More information about the C-safe-secure-studygroup mailing list