remove unnecessary code in protocolmessage
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / caprotocolmessage.c
index c45dc02..23bd47c 100644 (file)
@@ -59,7 +59,7 @@
 
 #define CA_BUFSIZE (128)
 #define CA_PDU_MIN_SIZE (4)
-#define CA_PORT_BUFFER_SIZE (2)
+#define CA_PORT_BUFFER_SIZE (4)
 
 static const char COAP_URI_HEADER[] = "coap://[::]/";
 
@@ -170,8 +170,8 @@ coap_pdu_t *CAGeneratePDU(const char *uri, uint32_t code, const CAInfo_t info)
             coap_delete_list(optlist);
             return NULL;
         }
-
-        pdu = CAGeneratePDUImpl((code_t) code, optlist, info, info.payload, strlen(info.payload));
+        size_t lenPayload = info.payload ? strlen(info.payload) : 0;
+        pdu = CAGeneratePDUImpl((code_t) code, optlist, info, info.payload, lenPayload);
         if (NULL == pdu)
         {
             OIC_LOG(ERROR, TAG, "pdu NULL");
@@ -596,7 +596,7 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *
                     // Make sure there is enough room in the optionResult buffer
                     if ((optionLength + bufLength) < sizeof(optionResult))
                     {
-                        memcpy(optionResult + optionLength, buf, bufLength);
+                        memcpy(&optionResult[optionLength], buf, bufLength);
                         optionLength += bufLength;
                     }
                     else
@@ -652,7 +652,7 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *
                     // Make sure there is enough room in the optionResult buffer
                     if ((optionLength + bufLength) < sizeof(optionResult))
                     {
-                        memcpy(optionResult + optionLength, buf, bufLength);
+                        memcpy(&optionResult[optionLength], buf, bufLength);
                         optionLength += bufLength;
                     }
                     else
@@ -902,10 +902,6 @@ CAMessageType_t CAGetMessageTypeFromPduBinaryData(const void *pdu, uint32_t size
     }
 
     coap_hdr_t *hdr = (coap_hdr_t *) pdu;
-    if (NULL == hdr)
-    {
-        return CA_MSG_NONCONFIRM;
-    }
 
     return (CAMessageType_t) hdr->type;
 }
@@ -926,10 +922,6 @@ uint16_t CAGetMessageIdFromPduBinaryData(const void *pdu, uint32_t size)
     }
 
     coap_hdr_t *hdr = (coap_hdr_t *) pdu;
-    if (NULL == hdr)
-    {
-        return 0;
-    }
 
     return hdr->id;
 }
@@ -950,11 +942,6 @@ CAResponseResult_t CAGetCodeFromPduBinaryData(const void *pdu, uint32_t size)
     }
 
     coap_hdr_t *hdr = (coap_hdr_t *) pdu;
-    if (NULL == hdr)
-    {
-        OIC_LOG(ERROR, TAG, "hdr is null");
-        return CA_NOT_FOUND;
-    }
 
     return (CAResponseResult_t) CA_RESPONSE_CODE(hdr->code);
 }