Uploaded image for project: 'SonarCFamily'
  1. SonarCFamily
  2. CPP-3431

Proposed rule: report passing uninitialized values to functions outside of the current TU

    XMLWordPrintable

    Details

      Description

      Proposed by a community member BoHsian Chen.

      Detect if an uninitialized value is passed to a function defined outside of the current translation unit (or also returned from a function?) and flag it as a hotspot (since in many cases a function expects its parameters to be initialized to some sensible values).

      Such rule shall produce FPs for the pattern of initializing a value passing it as an output pointer, and that is fine for a hotspot.

      test.h

      struct str{int a;};
      void func(struct str *);
      

      test.c:

      #include "test.h"
      void func(struct str *s)
      {
          if (s->a == x)
              DOSOMETHING
      }
      

      main1.c

      #include "test.h"
      int main(void)
      {
          struct str s;
          func(&s);
      }
      

      Report the argument &s of func(&s) in main1.c.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            arseniy.zaostrovnykh Arseniy Zaostrovnykh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: