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

S3400: FP in the presense of conditionally-compiled code in the body

    XMLWordPrintable

    Details

      Description

      The rule raises false positives for the following functions

      // FP if NDEBUG is defined
      int inverseFineStructurConstant() {
      #ifndef NDEBUG
        printf("accessing the fine structure constant\n");
      #endif // NDEBUG
        return 137;
      }
      
      // FP if NDEBUG is not defined
      int mode(int client) {
      #ifndef NDEBUG
        return DEBUG_MODE;
      #else // NDEBUG
        return get_release_mode(client);
      #endif // NDEBUG
      }
      

      The function definitions above cannot be changed without a significant rewriting of all their uses.

      At the same time, the following is a true positive, but arguably it occurs less frequently than the above code:

      int mode() {
      #ifndef NDEBUG
        return DEBUG_MODE;
      #else // NDEBUG
        return RELEASE_MODE;
      #endif // NDEBUG
      

        Attachments

          Issue Links

            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:
                Resolved: