Improve Buffer Size in occoaphelper
authoromkar <omkar.m.hegde@intel.com>
Wed, 10 Dec 2014 00:57:23 +0000 (16:57 -0800)
committeromkar <omkar.m.hegde@intel.com>
Mon, 15 Dec 2014 16:41:57 +0000 (08:41 -0800)
Previously, we had the BUF_SIZE set at 64. Changing it to be the
greater of MAX_URI_LENGTH and MAX_QUERY_LENGTH. So, if max length
needs to change, we need to change it only in ocstackconfig.

Change-Id: I18aeca83f82932896424d38389a872b581859860
Signed-off-by: omkar <omkar.m.hegde@intel.com>
resource/csdk/occoap/include/occoaphelper.h
resource/csdk/occoap/src/occoaphelper.c

index 7be3e30..2dc687e 100644 (file)
 #include "occoaptoken.h"
 #include "ocstackinternal.h"
 
-#define BUF_SIZE (64)
+/**
+ * The Max Size of the buffer that is used to parse uri and query
+ * individually.
+ */
+#define MAX_URI_QUERY_BUF_SIZE ((MAX_URI_LENGTH) >= (MAX_QUERY_LENGTH) ?\
+                            (MAX_URI_LENGTH) : (MAX_QUERY_LENGTH))
 
 // checks if optionID is within vendor specific range
 OCStackResult isVendorSpecific(uint16_t optionID);
index f1e9382..966bd79 100644 (file)
@@ -374,7 +374,7 @@ OCStackResult FormOptionList(coap_list_t * * optListLoc, uint8_t * addMediaType,
     coap_list_t * optNode = NULL;
     int res;
     size_t buflen;
-    unsigned char _buf[BUF_SIZE];
+    unsigned char _buf[MAX_URI_QUERY_BUF_SIZE];
     unsigned char *buf = _buf;
 
     if(addMediaType)
@@ -412,7 +412,7 @@ OCStackResult FormOptionList(coap_list_t * * optListLoc, uint8_t * addMediaType,
     if(uri && uriLength)
     {
         buf = _buf;
-        buflen = BUF_SIZE;
+        buflen = MAX_URI_QUERY_BUF_SIZE;
         res = coap_split_path(uri, uriLength, buf, &buflen);
         while (res--) {
             optNode = CreateNewOptionNode(COAP_OPTION_URI_PATH,
@@ -426,7 +426,7 @@ OCStackResult FormOptionList(coap_list_t * * optListLoc, uint8_t * addMediaType,
     if(query && queryLength)
     {
         buf = _buf;
-        buflen = BUF_SIZE;
+        buflen = MAX_URI_QUERY_BUF_SIZE;
         res = coap_split_query(query, queryLength, buf, &buflen);
         while (res--) {
             optNode = CreateNewOptionNode(COAP_OPTION_URI_QUERY,