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

S836: FN with uninitialized struct

    XMLWordPrintable

    Details

      Description

      As soon as a struct has more than two fields, FN appear when the unitialized struct is the return object of a function.
      See example here:

      struct Person {
        int id;
        char* name;
      };
      
      struct PersonWithAge {
        int id;
        int age;
        char* name;
      };
      
      Person create_a_person_unint() {
        Person person;
        return person;
      }
      
      PersonWithAge create_a_personWithAge_unint() {
        PersonWithAge person;
        return person;
      }
      
      int main() {
        auto pId = create_a_person_unint().id; // OK, issue is raised
        auto pIdWithAge = create_a_personWithAge_unint().id; // FN
      
        PersonWithAge p;
        pIdWithAge = p.id; // OK, issue is raised
      
        return 0;
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              amelie.renard Amélie Renard
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: