[IOT-2539] clean switch warning
authorGeorge Nash <george.nash@intel.com>
Mon, 31 Jul 2017 20:00:55 +0000 (13:00 -0700)
committerNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Fri, 22 Sep 2017 05:50:48 +0000 (05:50 +0000)
The file deviceonboardingstate.c produced a warning:
enumeration value 'DOS_STATE_COUNT' not handled in switch

This is a result of adding the the DOS_STATE_COUNT as an
enum value. This is a common programming pattern but will
result in the -Wswitch warning if the enum values are
used in a case statement without a default state.

There are multiple ways to handle this warning.
- add an empty case for the unhandled count state
- add a default case to the switch statement
- move the count out of the enum

For this fix the unhandled count state was added
to the switch statment with an assert if that case
is ever encountered.

Bug: https://jira.iotivity.org/browse/IOT-2539
Change-Id: I14c390b34d33db9a82a3bd055dd513a96c941733
Signed-off-by: George Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21685
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
(cherry picked from commit b76529cbc0004b40b8142fb6721deff67eddb0e4)

resource/csdk/security/src/deviceonboardingstate.c

index 17c7f36..f620fc1 100644 (file)
@@ -79,6 +79,10 @@ static bool IsValidStateTransition(OicSecDeviceOnboardingState_t oldState,
             ret = true;
         }
         break;
+        case DOS_STATE_COUNT:
+        // The DOS_STATE_COUNT should never be passed into this function
+        assert(false);
+        break;
     }
 
     OIC_LOG_V(INFO, TAG, "%s: returning %s.", __func__, ret?"true":"false");
@@ -564,6 +568,10 @@ static OCStackResult DoStateChange(OicSecDeviceOnboardingState_t newState)
             ret = OC_STACK_FORBIDDEN_REQ;
         }
         break;
+        case DOS_STATE_COUNT:
+        // The DOS_STATE_COUNT should never be passed into this function
+        assert(false);
+        break;
     }
 
     OIC_LOG_V(DEBUG, TAG, "%s: returning %d.", __func__, ret);
@@ -647,4 +655,4 @@ OCStackResult SetDosState(const OicSecDeviceOnboardingState_t desiredState)
 
 exit:
     return OC_STACK_INTERNAL_SERVER_ERROR;
-}
\ No newline at end of file
+}