Removed a single instance of the usage of a "magic number" in the stack.
authorJoseph Morrow <joseph.l.morrow@intel.com>
Mon, 23 Mar 2015 18:49:12 +0000 (14:49 -0400)
committerErich Keane <erich.keane@intel.com>
Tue, 24 Mar 2015 23:48:26 +0000 (23:48 +0000)
After walking through the logic in ValidateQuery() its clear that there
was an intention add a second #define, but this must have been over-
looked at that time. There a single #define to avoid usage of a
"magic number" (or a raw value, ie. "2") but it was actually being used
in the wrong spot in the code.

Change-Id: I2ff045005ccacc9822280d93e6b20bfac8df1cbd
Signed-off-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/539
Reviewed-by: Erich Keane <erich.keane@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
resource/csdk/stack/src/occollection.c

index fd18359..7103c81 100644 (file)
@@ -37,7 +37,8 @@
 
 #define TAG PCF("occollection")
 
-#define NUM_PARAM_IN_QUERY  2
+#define NUM_PARAM_IN_QUERY   2 // The expected number of parameters in a query
+#define NUM_FIELDS_IN_QUERY  2 // The expected number of fields in a query
 
 static OCStackResult CheckRTParamSupport(const OCResource* resource, const char* rtPtr)
 {
@@ -142,14 +143,14 @@ ValidateQuery (const char *query, OCResourceHandle resource,
                 innerToken = strtok_r (NULL, "=", &endToken);
             }
         }
-        if (numParam != 2)
+        if (numParam != NUM_PARAM_IN_QUERY)
         {
             // Query parameter should be of the form if=<string>. String should not have & or =
             return OC_STACK_INVALID_QUERY;
         }
         token = strtok_r (NULL, "&", &endStr);
     }
-    if (numFields > NUM_PARAM_IN_QUERY)
+    if (numFields > NUM_FIELDS_IN_QUERY)
     {
         // current release supports one IF value, one RT value and no other params
         return OC_STACK_INVALID_QUERY;