1.Optimization to reduce number of strlen() calls.
authorOmkar Hegde <omkar.m.hegde@intel.com>
Fri, 3 Oct 2014 18:19:52 +0000 (11:19 -0700)
committerOmkar Hegde <omkar.m.hegde@intel.com>
Fri, 3 Oct 2014 18:19:52 +0000 (11:19 -0700)
2. Removed the extra blank line.
3. '?' is no longer considered a part of the query
Change-Id: Ieabc1352a4cccc504ae1caac59b154aa7a9c0997

csdk/stack/src/ocstack.c

index 53b10a1..78aa0d0 100644 (file)
@@ -317,32 +317,34 @@ OCStackResult OCStop()
 /**
  * Verify the lengths of the URI and the query separately
  *
- * @param inputUri       - Input URI and query
+ * @param inputUri       - Input URI and query.
+ * @param uriLen         - The length of the initial URI with query.
  *
- * Note: The '?' that appears after the URI is considered as
+ * Note: The '?' that appears after the URI is not considered as
  * a part of the query.
  */
 OCStackResult verifyUriQueryLength(const char *inputUri, uint16_t uriLen)
 {
     char *query;
-    uint16_t queryLen = 0;
 
     query = strchr (inputUri, '?');
+
     if (query != NULL)
     {
-        queryLen = strlen (query);
-    }
+        if((query - inputUri) > MAX_URI_LENGTH)
+        {
+            return OC_STACK_INVALID_URI;
+        }
 
-    if (queryLen > MAX_QUERY_LENGTH)
-    {
-        return OC_STACK_INVALID_URI;
+        if((inputUri + uriLen - 1 - query) > MAX_QUERY_LENGTH)
+        {
+            return OC_STACK_INVALID_QUERY;
+        }
     }
-
-    if ((uriLen - queryLen) > MAX_URI_LENGTH)
+    else if(uriLen > MAX_URI_LENGTH)
     {
-        return OC_STACK_INVALID_QUERY;
+        return OC_STACK_INVALID_URI;
     }
-
     return OC_STACK_OK;
 }