{
return;
}
- char buffer[MAX_LOG_V_BUFFER_SIZE];
- memset(buffer, 0, sizeof buffer);
+ char buffer[MAX_LOG_V_BUFFER_SIZE] = {};
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof buffer - 1, format, args);
return;
}
+ // I've got no idea why static initialization doesn't work here. It seems that the compiler
+ // seems to think that this is a variable-sized object
char lineBuffer[LINE_BUFFER_SIZE];
memset(lineBuffer, 0, sizeof lineBuffer);
int lineIndex = 0;
return;
}
- char buffer[LINE_BUFFER_SIZE] = {0};
+ char buffer[LINE_BUFFER_SIZE] = {};
strcpy_P(buffer, (char*)pgm_read_word(&(LEVEL[level])));
Serial.print(buffer);
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "oic_logger.h"
+#include "oic_string.h"
#include <string.h>
#include <stdlib.h>
int oic_log_set_module(oic_log_ctx_t *ctx, const char *module_name)
{
char *mn;
- size_t l;
if (0 == ctx)
return 0;
/* Swap pointers so that module data's not erased in the event of failure: */
- l = strlen(module_name);
-
- mn = (char *) malloc(1 + l);
-
+ mn = OICStrdup(module_name);
if (0 == mn)
{
if (0 != ctx->module_name)
return 0;
}
- memcpy(mn, module_name, 1 + l);
-
if (0 != ctx->module_name)
free(ctx->module_name);
#include "caipinterface.h"
#include "dtls.h"
#include "oic_malloc.h"
+#include "oic_string.h"
#include "global.h"
/**
return CA_MEMORY_ALLOC_FAILED;
}
- strncpy(peerInfo->address.IP.ipAddress, peerAddr, CA_IPADDR_SIZE);
+ OICStrcpy(peerInfo->address.IP.ipAddress, sizeof(peerInfo->address.IP.ipAddress),
+ peerAddr);
peerInfo->address.IP.port = port;
- memcpy(peerInfo->identity.id, id, id_length);
+ OICStrcpyPartial(peerInfo->identity.id, sizeof(peerInfo->identity.id), id, id_length);
peerInfo->identity.id_length = id_length;
CAResult_t result = u_arraylist_add(g_caDtlsContext->peerInfoList, (void *)peerInfo);
#include <string.h>
#include <ctype.h>
+#include "oic_string.h"
+#include "oic_malloc.h"
#ifdef __ANDROID__
#include <jni.h>
#endif
-#include "oic_malloc.h"
-#include "oic_string.h"
-
#define CA_ADAPTER_UTILS_TAG "CA_ADAPTER_UTILS"
#ifdef __ANDROID__
{
if (CA_EDR == type)
{
- strncpy(info->addressInfo.BT.btMacAddress, address, CA_MACADDR_SIZE - 1);
- info->addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.BT.btMacAddress, sizeof(info->addressInfo.BT.btMacAddress),
+ address);
}
else if (CA_LE == type)
{
- strncpy(info->addressInfo.LE.leMacAddress, address, CA_MACADDR_SIZE - 1);
- info->addressInfo.LE.leMacAddress[CA_MACADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.LE.leMacAddress, sizeof(info->addressInfo.LE.leMacAddress),
+ address);
}
else if (CA_IPV4 == type)
{
- strncpy(info->addressInfo.IP.ipAddress, address, CA_IPADDR_SIZE - 1);
- info->addressInfo.IP.ipAddress[CA_IPADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.IP.ipAddress, sizeof(info->addressInfo.IP.ipAddress),
+ address);
}
else if (CA_IPV6 == type)
{
info->type = connectivity->type;
if (CA_EDR == info->type && strlen(connectivity->addressInfo.BT.btMacAddress))
{
- strncpy(info->addressInfo.BT.btMacAddress, connectivity->addressInfo.BT.btMacAddress,
- CA_MACADDR_SIZE - 1);
- info->addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.BT.btMacAddress, sizeof(info->addressInfo.BT.btMacAddress),
+ connectivity->addressInfo.BT.btMacAddress);
}
else if (CA_LE == info->type && strlen(connectivity->addressInfo.LE.leMacAddress))
{
- strncpy(info->addressInfo.LE.leMacAddress, connectivity->addressInfo.LE.leMacAddress,
- CA_MACADDR_SIZE - 1);
- info->addressInfo.LE.leMacAddress[CA_MACADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.LE.leMacAddress, sizeof(info->addressInfo.LE.leMacAddress),
+ connectivity->addressInfo.LE.leMacAddress);
}
else if ((CA_IPV4 == info->type)
&& strlen(connectivity->addressInfo.IP.ipAddress))
{
- strncpy(info->addressInfo.IP.ipAddress, connectivity->addressInfo.IP.ipAddress,
- CA_IPADDR_SIZE - 1);
- info->addressInfo.IP.ipAddress[CA_IPADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.IP.ipAddress, sizeof(info->addressInfo.IP.ipAddress),
+ connectivity->addressInfo.IP.ipAddress);
info->addressInfo.IP.port = connectivity->addressInfo.IP.port;
}
else if (CA_IPV6 == info->type)
{
if (CA_EDR == type)
{
- strncpy(info->addressInfo.BT.btMacAddress, address, CA_MACADDR_SIZE - 1);
- info->addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.BT.btMacAddress, sizeof(info->addressInfo.BT.btMacAddress),
+ address);
}
else if (CA_LE == type)
{
- strncpy(info->addressInfo.LE.leMacAddress, address, CA_MACADDR_SIZE - 1);
- info->addressInfo.LE.leMacAddress[CA_MACADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.LE.leMacAddress, sizeof(info->addressInfo.LE.leMacAddress),
+ address);
}
else if (CA_IPV4 == type)
{
- strncpy(info->addressInfo.IP.ipAddress, address, CA_IPADDR_SIZE - 1);
- info->addressInfo.IP.ipAddress[CA_IPADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.IP.ipAddress, sizeof(info->addressInfo.IP.ipAddress),
+ address);
}
else if (CA_IPV6 == type)
{
info->transportType = remoteEndpoint->transportType;
if (CA_EDR == info->transportType && ('\0' != remoteEndpoint->addressInfo.BT.btMacAddress[0]))
{
- strncpy(info->addressInfo.BT.btMacAddress, remoteEndpoint->addressInfo.BT.btMacAddress,
- CA_MACADDR_SIZE - 1);
- info->addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.BT.btMacAddress, sizeof(info->addressInfo.BT.btMacAddress),
+ remoteEndpoint->addressInfo.BT.btMacAddress);
}
else if (CA_LE == info->transportType
&& ('\0' != remoteEndpoint->addressInfo.LE.leMacAddress[0]))
{
- strncpy(info->addressInfo.LE.leMacAddress, remoteEndpoint->addressInfo.LE.leMacAddress,
- CA_MACADDR_SIZE - 1);
- info->addressInfo.LE.leMacAddress[CA_MACADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.LE.leMacAddress, sizeof(info->addressInfo.LE.leMacAddress),
+ remoteEndpoint->addressInfo.LE.leMacAddress);
}
else if ((CA_IPV4 == info->transportType)
&& ('\0' != remoteEndpoint->addressInfo.IP.ipAddress[0]))
{
- strncpy(info->addressInfo.IP.ipAddress, remoteEndpoint->addressInfo.IP.ipAddress,
- CA_IPADDR_SIZE - 1);
- info->addressInfo.IP.ipAddress[CA_IPADDR_SIZE - 1] = '\0';
+ OICStrcpy(info->addressInfo.IP.ipAddress, sizeof(info->addressInfo.IP.ipAddress),
+ remoteEndpoint->addressInfo.IP.ipAddress);
info->addressInfo.IP.port = remoteEndpoint->addressInfo.IP.port;
}
else if (CA_IPV6 == info->transportType)
#include "caedrclient.h"
#include "logger.h"
#include "oic_malloc.h"
+#include "oic_string.h"
#include "cathreadpool.h" /* for thread pool */
#include "camutex.h"
#include "uarraylist.h"
if (jni_address)
{
const char* localAddress = (*env)->GetStringUTFChars(env, jni_address, NULL);
- *address = (char*) OICMalloc(strlen(localAddress) + 1);
+ *address = OICStrdup(localAddress);
if (*address == NULL)
{
if (isAttached)
}
return;
}
- memcpy(*address, localAddress, strlen(localAddress));
+
(*env)->ReleaseStringUTFChars(env, jni_address, localAddress);
}
#include "uarraylist.h"
#include "caadapterutils.h"
#include "org_iotivity_ca_CaEdrInterface.h"
+#include "oic_string.h"
//#define DEBUG_MODE
#define TAG PCF("CA_EDR_SERVER")
OIC_LOG_V(DEBUG, TAG, "[EDR][Native] btReadData: read %s, %d", buf, length);
char responseData[MAX_PDU_BUFFER] = { 0 };
- memcpy(responseData, (const char*) buf, length);
+ OICStrcpy(responseData, sizeof(responseData), buf, length);
switch (type)
{
#include "caedrutils.h"
#include "logger.h"
#include "oic_malloc.h"
+#include "oic_string.h"
#include "cathreadpool.h"
#include "uarraylist.h"
OIC_LOG(ERROR, TAG, "[EDR][Native] newstate is null");
return;
}
- strcpy(newstate->address, address);
+ OICStrcpy(newstate->address, sizeof(newstate->address), address);
newstate->state = state;
CAEDRNativeAddDeviceStateToList(newstate);
g_threadPoolHandle = handle;
// register handlers
- CAConnectivityHandler_t handler;
- memset(&handler, 0, sizeof(CAConnectivityHandler_t));
+ CAConnectivityHandler_t handler = {};
handler.startAdapter = CAStartEDR;
handler.startListenServer = CAStartEDRListeningServer;
return CA_STATUS_FAILED;
}
- strcpy(newstate->address, address);
+ OICStrcpy(newstate->address, sizeof(newstate->address), address);
newstate->connectedState = connectedState;
newstate->notificationState = notificationState;
newstate->sendState = sendState;
#include "caqueueingthread.h"
#include "camsgparser.h"
#include "oic_malloc.h"
+#include "oic_string.h"
/**
* @var CALEADAPTER_TAG
return CA_STATUS_FAILED;
}
- strncpy((*info)->addressInfo.BT.btMacAddress, local_address,
- sizeof((*info)->addressInfo.BT.btMacAddress) - 1);
- (*info)->addressInfo.BT.btMacAddress[sizeof((*info)->addressInfo.BT.btMacAddress)-1] = '\0';
+ OICStrcpy((*info)->addressInfo.BT.btMacAddress, sizeof ((*info)->addressInfo.BT.btMacAddress),
+ local_address);
ca_mutex_lock(g_bleLocalAddressMutex);
- strncpy(g_localBLEAddress, local_address, sizeof(g_localBLEAddress) - 1);
- g_localBLEAddress[sizeof(g_localBLEAddress)-1] = '\0';
+ OICStrcpy(g_localBLEAddress, sizeof(g_localBLEAddress), local_address);
ca_mutex_unlock(g_bleLocalAddressMutex);
(*info)->type = CA_LE;
CALocalConnectivity_t localEndpoint = {};
ca_mutex_lock(g_bleLocalAddressMutex);
- strncpy(localEndpoint.addressInfo.BT.btMacAddress, g_localBLEAddress, strlen(g_localBLEAddress));
+ OICStrcpy(localEndpoint.addressInfo.BT.btMacAddress,
+ sizeof(localEndpoint.addressInfo.BT.btMacAddress),
+ g_localBLEAddress);
ca_mutex_unlock(g_bleLocalAddressMutex);
// Start a GattServer/Client if gLeServerStatus is SET
g_threadPoolHandle = handle;
// register handlers
- CAConnectivityHandler_t handler;
- memset(&handler, 0, sizeof(CAConnectivityHandler_t));
+ CAConnectivityHandler_t handler = {};
handler.startAdapter = CAStartLE;
handler.startListenServer = CAStartLEListeningServer;
VERIFY_NON_NULL_RET(stTemp, TZ_BLE_CLIENT_TAG, "calloc failed!", false);
- size_t len = strlen(bdAddress);
- stTemp->address = (char *)OICMalloc(sizeof(char) * (len + 1));
+ stTemp->address = OICStrdup(bdAddress);
if (NULL == stTemp->address)
{
OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "Malloc failed!");
return false;
}
- strncpy(stTemp->address, bdAddress, len + 1);
bt_gatt_clone_attribute_handle(&(stTemp->serviceInfo), characteristic);
ca_mutex_lock(g_bleClientThreadPoolMutex);
VERIFY_NON_NULL_RET(stTemp, TZ_BLE_CLIENT_TAG, "Calloc Failed", false);
char *bdAddress = (char *)userData;
- size_t len = strlen(bdAddress);
- stTemp->address = (char *)OICMalloc(sizeof(char) * (len + 1));
+ stTemp->address = OICStrdup(bdAddress);
if (NULL == stTemp->address)
{
OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "Malloc failed!");
return false;
}
- strncpy(stTemp->address, bdAddress, len + 1);
-
BLEServiceInfo *bleServiceInfo = NULL;
result = CACreateBLEServiceInfo(bdAddress, service, &bleServiceInfo);
CAResult_t res = CAVerifyOICServiceByUUID(discoveryInfo->service_uuid[i]);
if (CA_STATUS_OK == res)
{
-
- size_t len = strlen(discoveryInfo->remote_address);
-
- char *addr = (char *)OICMalloc(sizeof(char) * (len + 1));
+ char *addr = OICStrdup(discoveryInfo->remote_address);
VERIFY_NON_NULL_VOID(addr, TZ_BLE_CLIENT_TAG, "Malloc failed");
- strncpy(addr, discoveryInfo->remote_address, len + 1);
OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG,
"Trying to do Gatt connection to [%s]", addr);
VERIFY_NON_NULL_RET(remoteAddress, TZ_BLE_CLIENT_TAG,
"remote address is NULL", CA_STATUS_FAILED);
- size_t len = strlen(remoteAddress);
- char *addr = (char *)OICMalloc(sizeof(char) * (len + 1));
+ char *addr = OICStrdup(remoteAddress);
VERIFY_NON_NULL_RET(addr, TZ_BLE_CLIENT_TAG, "Malloc failed", CA_STATUS_FAILED);
- strncpy(addr, remoteAddress, len + 1);
-
int32_t ret = bt_gatt_foreach_primary_services(remoteAddress, CABleGattPrimaryServiceCb,
(void *)addr); // addr memory will be free in callback.
if (BT_ERROR_NONE != ret)
VERIFY_NON_NULL_RET(remoteAddress, NULL, "remoteAddress is NULL", CA_STATUS_FAILED);
- size_t len = strlen(remoteAddress);
-
- char *addr = (char *)OICMalloc(sizeof(char) * (len + 1));
+ char *addr = OICStrdup(remoteAddress);
VERIFY_NON_NULL_RET(addr, TZ_BLE_CLIENT_TAG, "Malloc failed", CA_STATUS_FAILED);
- strncpy(addr, remoteAddress, len + 1);
int32_t ret = bt_gatt_discover_characteristics(service, CABleGattCharacteristicsDiscoveredCb,
(void *)addr); // addr will be freed in callback.
OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "charPath = [%s] charValue = [%s] len [%d]", charPath,
charValue, charValueLen);
- char *data = (char *)OICMalloc(sizeof(char) * charValueLen);
+ char *data = (char *)OICMalloc(sizeof(char) * charValueLen + 1);
if (NULL == data)
{
OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "Malloc failed!");
return;
}
- strncpy(data, (char *)charValue, charValueLen);
+ OICStrcpy(data, charValueLen + 1, charValue);
ca_mutex_lock(g_bleReqRespCbMutex);
if (NULL == g_bleServerDataReceivedCallback)
return CA_STATUS_FAILED;
}
- char *data = (char *) OICMalloc(sizeof(char) * (charValueLen + 1));
+ char *data = (char *) OICCalloc(sizeof(char), (charValueLen + 1));
if (NULL == data)
{
OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "malloc failed!");
ca_mutex_unlock(g_bleCharacteristicMutex);
return CA_STATUS_FAILED;
}
- memset(data, 0x0, (charValueLen + 1));
- strncpy(data, charValue, charValueLen);
+ OICStrcpy(data, charValueLen + 1, charValue);
OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "updating characteristics char [%s] data [%s] dataLen [%d]",
(const char *)g_gattReadCharPath, data, charValueLen);
return CA_STATUS_FAILED;
}
- strncpy(data, charValue, charValueLen + 1);
+ OICStrcpy(data, charValueLen + 1, charValue);
OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "updating characteristics char [%s] data [%s] dataLen [%d]",
(const char *)g_gattReadCharPath, data, charValueLen);
return CA_STATUS_FAILED;
}
- size_t len = strlen(bdAddress);
- (*bleServiceInfo)->bdAddress = (char *) OICMalloc(sizeof(char) * (len + 1));
+ (*bleServiceInfo)->bdAddress = OICStrdup(bdAddress);
if (NULL == (*bleServiceInfo)->bdAddress)
{
return CA_STATUS_FAILED;
}
- strncpy((*bleServiceInfo)->bdAddress, bdAddress, len + 1);
-
if (service)
{
int32_t ret = bt_gatt_clone_attribute_handle(&((*bleServiceInfo)->service_clone), service);
#define CA_TRANSPORT_TYPE_NUM 4
-static CAConnectivityHandler_t g_adapterHandler[CA_TRANSPORT_TYPE_NUM];
+static CAConnectivityHandler_t g_adapterHandler[CA_TRANSPORT_TYPE_NUM] = {};
static CANetworkPacketReceivedCallback g_networkPacketReceivedCallback = NULL;
return;
}
- memcpy(&g_adapterHandler[index], &handler, sizeof(CAConnectivityHandler_t));
+ g_adapterHandler[index] = handler;
OIC_LOG_V(DEBUG, TAG, "%d type adapter, register complete!", cType);
}
return;
}
- memcpy(&g_adapterHandler[index], &handler, sizeof(CAConnectivityHandler_t));
+ g_adapterHandler[index] = handler;
OIC_LOG_V(DEBUG, TAG, "%d type adapter", cType);
OIC_LOG(DEBUG, TAG, "OUT");
#include "caqueueingthread.h"
#include "camutex.h"
#include "oic_malloc.h"
+#include "oic_string.h"
#include "canetworkconfigurator.h"
#define TAG PCF("CA")
return;
}
- char uri[CA_MAX_URI_LENGTH] = { 0, };
- uint32_t bufLen = sizeof(uri);
+ char uri[CA_MAX_URI_LENGTH] = { };
if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
{
return;
}
- CAResult_t res = CAGetRequestInfoFromPDU(pdu, ReqInfo, uri, bufLen);
+ CAResult_t res = CAGetRequestInfoFromPDU(pdu, ReqInfo, uri, sizeof(uri));
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, TAG, "CAGetRequestInfoFromPDU failed : %d", res);
OIC_LOG_V(DEBUG, TAG, "Request- msgID : %d", ReqInfo->info.messageId);
if (NULL != endpoint)
{
- endpoint->resourceUri = (char *) OICMalloc(bufLen + 1);
+ endpoint->resourceUri = (char *) OICMalloc(sizeof(uri) + 1);
if (NULL == endpoint->resourceUri)
{
OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed!");
CAAdapterFreeRemoteEndpoint(endpoint);
return;
}
- memcpy(endpoint->resourceUri, uri, bufLen);
- endpoint->resourceUri[bufLen] = '\0';
+ memcpy(endpoint->resourceUri, uri, sizeof(uri));
+ endpoint->resourceUri[sizeof(uri)] = '\0';
OIC_LOG_V(DEBUG, TAG, "URI : %s", endpoint->resourceUri);
}
// store the data at queue.
return;
}
- CAResult_t res = CAGetResponseInfoFromPDU(pdu, ResInfo, uri, bufLen);
+ CAResult_t res = CAGetResponseInfoFromPDU(pdu, ResInfo, uri, sizeof(uri));
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, TAG, "CAGetResponseInfoFromPDU failed : %d", res);
if (NULL != endpoint)
{
- endpoint->resourceUri = (char *) OICMalloc(bufLen + 1);
+ endpoint->resourceUri = (char *) OICMalloc(sizeof(uri) + 1);
if (NULL == endpoint->resourceUri)
{
OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
CAAdapterFreeRemoteEndpoint(endpoint);
return;
}
- memcpy(endpoint->resourceUri, uri, bufLen);
- endpoint->resourceUri[bufLen] = '\0';
+ memcpy(endpoint->resourceUri, uri, sizeof(uri));
+ endpoint->resourceUri[sizeof(uri)] = '\0';
OIC_LOG_V(DEBUG, TAG, "URI : %s", endpoint->resourceUri);
}
if(NULL == rep->resourceUri)
{
- uint32_t bufLen = sizeof(uri);
-
- CAURI_t resourceUri = (CAURI_t) OICMalloc(bufLen + 1);
+ CAURI_t resourceUri = OICStrdup(uri);
if (NULL == resourceUri)
{
OIC_LOG(ERROR, TAG, "CAErrorHandler, Memory allocation failed!");
return;
}
- memcpy(resourceUri, uri, bufLen);
- resourceUri[bufLen] = '\0';
OIC_LOG_V(DEBUG, TAG, "URI : %s", resourceUri);
rep->resourceUri = resourceUri;
}
return;
}
- char uri[CA_MAX_URI_LENGTH] = { 0, };
- uint32_t bufLen = sizeof(uri);
+ char uri[CA_MAX_URI_LENGTH] = { };
if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
{
return;
}
- CAResult_t res = CAGetRequestInfoFromPDU(pdu, ReqInfo, uri, bufLen);
+ CAResult_t res = CAGetRequestInfoFromPDU(pdu, ReqInfo, uri, sizeof(uri));
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, TAG, "CAGetRequestInfoFromPDU failed : %d", res);
OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *) ReqInfo->info.token, CA_MAX_TOKEN_LEN);
if (NULL != endpoint)
{
- endpoint->resourceUri = (char *) OICMalloc(bufLen + 1);
+ endpoint->resourceUri = (char *) OICMalloc(sizeof(uri) + 1);
if (NULL == endpoint->resourceUri)
{
OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed!");
coap_delete_pdu(pdu);
return;
}
- memcpy(endpoint->resourceUri, uri, bufLen);
- endpoint->resourceUri[bufLen] = '\0';
+ memcpy(endpoint->resourceUri, uri, sizeof(uri));
+ endpoint->resourceUri[sizeof(uri)] = '\0';
OIC_LOG_V(DEBUG, TAG, "URI : %s", endpoint->resourceUri);
}
return;
}
- CAResult_t res = CAGetResponseInfoFromPDU(pdu, ResInfo, uri, bufLen);
+ CAResult_t res = CAGetResponseInfoFromPDU(pdu, ResInfo, uri, sizeof(uri));
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, TAG, "CAGetResponseInfoFromPDU failed : %d", res);
if (NULL != endpoint)
{
- endpoint->resourceUri = (char *) OICMalloc(bufLen + 1);
+ endpoint->resourceUri = (char *) OICMalloc(sizeof(uri) + 1);
if (NULL == endpoint->resourceUri)
{
OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, Memory allocation failed !");
coap_delete_pdu(pdu);
return;
}
- memcpy(endpoint->resourceUri, uri, bufLen);
- endpoint->resourceUri[bufLen] = '\0';
+ memcpy(endpoint->resourceUri, uri, sizeof(uri));
+ endpoint->resourceUri[sizeof(uri)] = '\0';
OIC_LOG_V(DEBUG, TAG, "URI : %s", endpoint->resourceUri);
}
#include "caprotocolmessage.h"
#include "logger.h"
#include "oic_malloc.h"
+#include "oic_string.h"
// ARM GCC compiler doesnt define srandom function.
#if defined(ARDUINO) && !defined(ARDUINO_ARCH_SAM)
OIC_LOG(ERROR, TAG, "out of memory");
return NULL;
}
- strcat(coapUri, COAP_URI_HEADER);
- strcat(coapUri, uri);
+ OICStrcat(coapUri, uriLength, COAP_URI_HEADER);
+ OICStrcat(coapUri, uriLength, uri);
// parsing options in URI
CAResult_t res = CAParseURI(coapUri, &optlist);
if (buflen >= length)
{
memcpy(outUri, optionResult, length);
- outUri[length] = '\0';
#ifdef ARDUINO
OIC_LOG_V(DEBUG, TAG, "made URL:%s\n", optionResult);
#else
#include <string.h>
#include "oic_malloc.h"
+#include "oic_string.h"
#include "caremotehandler.h"
#include "logger.h"
OIC_LOG(ERROR, TAG, "CACloneRemoteEndpoint Out of memory");
return NULL;
}
- memcpy(clone, rep, sizeof(CARemoteEndpoint_t));
+ *clone = *rep;
if (NULL != rep->resourceUri)
{
// allocate reference uri field
- size_t len = strlen(rep->resourceUri);
-
- char *temp = (char *) OICCalloc(len + 1, sizeof(char));
+ char *temp = OICStrdup(rep->resourceUri);
if (NULL == temp)
{
OIC_LOG(ERROR, TAG, "CACloneRemoteEndpoint Out of memory");
return NULL;
}
- strncpy(temp, rep->resourceUri, len);
-
// save the uri
clone->resourceUri = temp;
}
{
if(ipLen && ipLen < sizeof(outAddress->IP.ipAddress))
{
- strncpy(outAddress->IP.ipAddress, pAddress, ipLen);
- outAddress->IP.ipAddress[ipLen] = '\0';
+ OICStrcpyPartial(outAddress->IP.ipAddress, sizeof(outAddress->IP.ipAddress),
+ pAddress, ipLen);
}
else if (!ipLen && len < sizeof(outAddress->IP.ipAddress))
{
- strncpy(outAddress->IP.ipAddress, pAddress, len);
- outAddress->IP.ipAddress[len] = '\0';
+ OICStrcpy(outAddress->IP.ipAddress, sizeof(outAddress->IP.ipAddress),
+ pAddress);
}
else
{
}
else
{
- strncpy(outAddress->BT.btMacAddress, pAddress, CA_MACADDR_SIZE - 1);
+ OICStrcpy(outAddress->BT.btMacAddress, sizeof(outAddress->BT.btMacAddress),
+ pAddress);
OIC_LOG_V(DEBUG, TAG, "mac address : %s", outAddress->BT.btMacAddress);
}
}
// allocate reference uri field
- size_t len = strlen(resourceUri);
-
- char *temp = (char *) OICMalloc(sizeof(char) * (len + 1));
+ char *temp = OICStrdup(resourceUri);
if (NULL == temp)
{
OIC_LOG(ERROR, TAG, "CACreateRemoteEndpointInternal Out of memory");
return NULL;
}
- strncpy(temp, resourceUri, len);
- temp[len] = '\0';
// save the uri
rep->resourceUri = temp;
// save the addressInfo
- memcpy(&(rep->addressInfo), &addr, sizeof(CAAddress_t));
+ rep->addressInfo = addr;
// save the type
rep->transportType = type;
return NULL;
}
- memcpy(clone, rep, sizeof(CARequestInfo_t));
+ *clone = *rep;
if (rep->info.token)
{
if (NULL != rep->info.payload)
{
// allocate payload field
- size_t len = strlen(rep->info.payload);
-
- char *temp = (char *) OICMalloc(sizeof(char) * (len + 1));
+ char *temp = OICStrdup(rep->info.payload);
if (NULL == temp)
{
OIC_LOG(ERROR, TAG, "CACloneRequestInfo Out of memory");
return NULL;
}
- strncpy(temp, rep->info.payload, len);
- temp[len] = '\0';
// save the payload
clone->info.payload = temp;
OIC_LOG(ERROR, TAG, "CACloneResponseInfo Out of memory");
return NULL;
}
- memcpy(clone, rep, sizeof(CAResponseInfo_t));
+ *clone = *rep;
if (rep->info.token)
{
if (NULL != rep->info.payload)
{
// allocate payload field
- int32_t len = strlen(rep->info.payload);
-
- char *temp = (char *) OICCalloc(len + 1, sizeof(char));
+ char *temp = OICStrdup(rep->info.payload);
if (NULL == temp)
{
OIC_LOG(ERROR, TAG, "CACloneResponseInfo Out of memory");
return NULL;
}
- strncpy(temp, rep->info.payload, len);
// save the payload
clone->info.payload = temp;
memset(context, 0, sizeof(CARetransmission_t));
- CARetransmissionConfig_t cfg;
- memset(&cfg, 0, sizeof(CARetransmissionConfig_t));
+ CARetransmissionConfig_t cfg = {};
if (NULL == config)
{
char interfaceSubnetMask[CA_IPADDR_SIZE] = { 0 };
socklen_t len = sizeof(struct sockaddr_in);
- strcpy(temp_ifr.ifr_name, item->ifr_name);
+ OICStrcpy(temp_ifr.ifr_name, sizeof(temp_ifr.ifr_name), item->ifr_name);
if (ioctl(sck, SIOCGIFFLAGS, &temp_ifr))
{
}
// set interface name
- strncpy(netInfo->interfaceName, item->ifr_name, strlen(item->ifr_name));
+ OICStrcpy(netInfo->interfaceName, sizeof(netInfo->interfaceName), item->ifr_name);
// set local ip address
- strncpy(netInfo->ipAddress, interfaceAddress, strlen(interfaceAddress));
+ OICStrcpy(netInfo->ipAddress, sizeof(netInfo->ipAddress), interfaceAddress);
// set subnet mask
- strncpy(netInfo->subnetMask, interfaceSubnetMask, strlen(interfaceSubnetMask));
+ OICStrcpy(netInfo->subnetMask, sizeof(netInfo->subnetMask), interfaceSubnetMask);
CAResult_t result = u_arraylist_add(*netInterfaceList, (void *) netInfo);
if (CA_STATUS_OK != result)
ca_mutex_unlock(g_networkMonitorContextMutex);
return false;
}
- memcpy(newNetInfo, info, sizeof(*newNetInfo));
+ *newNetInfo = *info;
OIC_LOG(DEBUG, IP_MONITOR_TAG, "New Interface found");
return CA_MEMORY_ALLOC_FAILED;
}
- memcpy(newNetinfo, info, sizeof(*info));
+ *newNetinfo = *info;
CAResult_t result = u_arraylist_add(*netInterfaceList, (void *) newNetinfo);
if (CA_STATUS_OK != result)
#include "uarraylist.h"
#include "logger.h"
#include "oic_malloc.h"
+#include "oic_string.h"
/**
* @def IP_ADAPTER_TAG
conInfo[count].type = CA_IPV4;
conInfo[count].isSecured = false;
conInfo[count].addressInfo.IP.port = CAGetServerPortNum(netInfo->ipAddress, false);
- strncpy(conInfo[count].addressInfo.IP.ipAddress, netInfo->ipAddress,
- strlen(netInfo->ipAddress));
+ OICStrcpy(conInfo[count].addressInfo.IP.ipAddress,
+ sizeof(conInfo[count].addressInfo.IP.ipAddress),
+ netInfo->ipAddress);
#ifdef __WITH_DTLS__
// copy secure unicast server information
conInfo[count].type = CA_IPV4;
conInfo[count].isSecured = true;
conInfo[count].addressInfo.IP.port = CAGetServerPortNum(netInfo->ipAddress, true);
- strncpy(conInfo[count].addressInfo.IP.ipAddress, netInfo->ipAddress,
- strlen(netInfo->ipAddress));
+ OICStrcpy(conInfo[count].addressInfo.IP.ipAddress,
+ sizeof(conInfo[count].addressInfo.IP.ipAddress),
+ netInfo->ipAddress);
}
#endif
count ++;
#endif
#include "camutex.h"
#include "oic_malloc.h"
+#include "oic_string.h"
/**
* @def IP_SERVER_TAG
return;
}
- memcpy(newInfo, info, sizeof(CAServerInfo_t));
+ *newInfo = *info;
CAResult_t result = u_arraylist_add(tempServerInfoList, (void *) newInfo);
if (CA_STATUS_OK != result)
}
if (netMask)
{
- strncpy(info->subNetMask, netMask, sizeof(info->subNetMask) - 1);
- info->subNetMask[sizeof(info->subNetMask)-1] = '\0';
+ OICStrcpy(info->subNetMask, sizeof(info->subNetMask), netMask);
OICFree(netMask);
}
- strncpy(info->ipAddress, localAddress, sizeof(info->ipAddress) - 1);
- info->ipAddress[sizeof(info->ipAddress) - 1] = '\0';
+ OICStrcpy(info->ipAddress, sizeof(info->ipAddress), localAddress);
info->port = *port;
info->socketFd = unicastServerFd;
info->isSecured = isSecured;
info->isServerStarted = true;
info->isMulticastServer = false;
- strncpy(info->ifAddr, localAddress, sizeof(info->ifAddr) - 1);
- info->ifAddr[sizeof(info->ifAddr) - 1] = '\0';
+ OICStrcpy(info->ifAddr, sizeof(info->ifAddr), localAddress);
CAResult_t res = CAAddServerInfo(g_serverInfoList, info);
if (CA_STATUS_OK != res)
}
if (netMask)
{
- strncpy(info->subNetMask, netMask, sizeof(info->subNetMask) - 1);
- info->subNetMask[sizeof(info->subNetMask) -1] = '\0';
+ OICStrcpy(info->subNetMask, sizeof(info->subNetMask), netMask);
OICFree(netMask);
}
- strncpy(info->ipAddress, multicastAddress, sizeof(info->ipAddress) - 1);
- info->ipAddress[sizeof(info->ipAddress) -1] = '\0';
+ OICStrcpy(info->ipAddress, sizeof(info->ipAddress), multicastAddress);
info->port = multicastPort;
info->socketFd = mulicastServerFd;
info->isSecured = false;
info->isServerStarted = true;
info->isMulticastServer = true;
- strncpy(info->ifAddr, localAddress, sizeof(info->ifAddr)-1);
- info->ifAddr[sizeof(info->ifAddr) -1] = '\0';
+ OICStrcpy(info->ifAddr, sizeof(info->ifAddr), localAddress);
ret = CAAddServerInfo(g_serverInfoList, info);
return CA_MEMORY_ALLOC_FAILED;
}
- memcpy(newNetinfo, info, sizeof(*info));
+ *newNetinfo = *info;
CAResult_t result = u_arraylist_add(*serverInfoList, (void *) newNetinfo);
if (CA_STATUS_OK != result)
return;
}
// set interface name
- strncpy(netInfo->interfaceName, ifa->ifa_name, sizeof(netInfo->interfaceName) - 1);
- netInfo->interfaceName[sizeof(netInfo->interfaceName)-1] = '\0';
+ OICStrcpy(netInfo->interfaceName, sizeof(netInfo->interfaceName), ifa->ifa_name);
// set local ip address
- strncpy(netInfo->ipAddress, interfaceAddress, strlen(interfaceAddress));
+ OICStrcpy(netInfo->ipAddress, sizeof(netInfo->ipAddress), interfaceAddress);
// set subnet mask
- strncpy(netInfo->subnetMask, interfaceSubnetMask, strlen(interfaceSubnetMask));
+ OICStrcpy(netInfo->subnetMask, sizeof(netInfo->subnetMask), interfaceSubnetMask);
CAResult_t result = u_arraylist_add(*netInterfaceList, (void *)netInfo);
if (CA_STATUS_OK != result)
ca_mutex_unlock(g_networkMonitorContextMutex);
return false;
}
- memcpy(newNetInfo, info, sizeof(*newNetInfo));
+ *newNetInfo = *info;
OIC_LOG(DEBUG, IP_MONITOR_TAG, "New Interface found");
return CA_MEMORY_ALLOC_FAILED;
}
- memcpy(newNetinfo, info, sizeof(*info));
+ *newNetinfo = *info;
CAResult_t result = u_arraylist_add(*netInterfaceList, (void *)newNetinfo);
if (CA_STATUS_OK != result)
ca_mutex_unlock(g_networkMonitorContextMutex);
return false;
}
- memcpy(newNetInfo, info, sizeof(*newNetInfo));
+ *newNetInfo = *info;
OIC_LOG(DEBUG, IP_MONITOR_TAG, "New Interface found");
}
// set interface name
- strncpy(netInfo->interfaceName, interfaceName, strlen(interfaceName));
+ OICStrcpy(netInfo->interfaceName, sizeof(netInfo->interfaceName), interfaceName);
// set local ip address
- strncpy(netInfo->ipAddress, ipAddress, strlen(ipAddress));
+ OICStrcpy(netInfo->ipAddress, sizeof(netInfo->ipAddress), ipAddress);
// set subnet mask
- strncpy(netInfo->subnetMask, subnetMask, strlen(subnetMask));
+ OICStrcpy(netInfo->subnetMask, sizeof(netInfo->subnetMask), subnetMask);
CAResult_t result = u_arraylist_add(*netInterfaceList, (void *)netInfo);
if (CA_STATUS_OK != result)
}
// set interface name
- strncpy(netInfo->interfaceName, interfaceName, strlen(interfaceName));
+ OICStrcpy(netInfo->interfaceName, sizeof(netInfo->interfaceName), interfaceName);
// set local ip address
- strncpy(netInfo->ipAddress, ipAddress, strlen(ipAddress));
+ OICStrcpy(netInfo->ipAddress, sizeof(netInfo->ipAddress), ipAddress);
// set subnet mask
- strncpy(netInfo->subnetMask, subnetMask, strlen(subnetMask));
+ OICStrcpy(netInfo->subnetMask, sizeof(netInfo->subnetMask), subnetMask);
bool ret = CACheckIsInterfaceInfoChanged(netInfo);
if (ret)
return CA_MEMORY_ALLOC_FAILED;
}
- memcpy(newNetinfo, info, sizeof(*info));
+ *newNetinfo = *info;
CAResult_t result = u_arraylist_add(*netInterfaceList, (void *)newNetinfo);
if (CA_STATUS_OK != result)
if (!format || !tag) {
return;
}
- char buffer[MAX_LOG_V_BUFFER_SIZE];
- memset(buffer, 0, sizeof buffer);
+ char buffer[MAX_LOG_V_BUFFER_SIZE] = {};
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof buffer - 1, format, args);
return;
}
+ // No idea why the static initialization won't work here, it seems the compiler is convinced
+ // that this is a variable-sized object.
char lineBuffer[LINE_BUFFER_SIZE];
memset(lineBuffer, 0, sizeof lineBuffer);
int lineIndex = 0;
TEST(RandomGeneration,OCFillRandomMem) {
uint16_t ARR_SIZE = 20;
- uint8_t array[ARR_SIZE];
- memset(array, 0, ARR_SIZE);
+ uint8_t array[ARR_SIZE]={};
OCFillRandomMem(array + 1, ARR_SIZE - 2);
for (int i = 1; i < ARR_SIZE - 2; i++) {
}
Serial.print("Testing OCFillRandomMem ... ");
- uint8_t array[ARR_SIZE];
- memset(array, 0, ARR_SIZE);
+ uint8_t array[ARR_SIZE] = {};
OCFillRandomMem(array + 1, ARR_SIZE - 2);
uint8_t overall = 0;
uint8_t value82 = 0;
}
TEST(RandomGeneration,OCFillRandomMem) {
- uint8_t array[ARR_SIZE];
- memset(array, 0, ARR_SIZE);
+ uint8_t array[ARR_SIZE] = {};
OCFillRandomMem(array + 1, ARR_SIZE - 2);
for (int i = 1; i <= ARR_SIZE - 2; i++) {
OCResourceProperty resourceProperties, uint8_t enable);
#endif
-/**
- * Clones a string IFF its pointer value is not NULL.
- *
- * Note: The caller to this function is responsible for calling @ref OCFree
- * for the destination parameter.
- *
- * @param dest The destination string for the string value to be cloned.
- *
- * @param src The source for the string value to be to cloned.
- */
-OCStackResult CloneStringIfNonNull(char **dest, const char *src);
-
-
const char *convertTriggerEnumToString(OCPresenceTrigger trigger);
OCPresenceTrigger convertTriggerStringToEnum(const char * triggerStr);
#include "logger.h"
#include "cJSON.h"
#include "oic_malloc.h"
+#include "oic_string.h"
/// Module Name
#include <stdio.h>
jsonLen = strlen(jsonStr);
if (jsonLen < *remaining)
{
- strncpy(bufferPtr, jsonStr, jsonLen);
+ OICStrcpy(bufferPtr, *remaining, jsonStr);
*remaining -= jsonLen;
bufferPtr += jsonLen;
ret = OC_STACK_OK;
#include "ocresourcehandler.h"
#include "ocrandom.h"
#include "oic_malloc.h"
+#include "oic_string.h"
#include "ocserverrequest.h"
#include "cJSON.h"
if (jsonLen < *remaining)
{
- strncpy(out, jsonStr, (jsonLen + 1));
+ OICStrcpy(out, *remaining, jsonStr);
*remaining = *remaining - jsonLen;
ret = OC_STACK_OK;
}
ehResponse.persistentBufferFlag = 0;
ehResponse.requestHandle = (OCRequestHandle) request;
ehResponse.resourceHandle = (OCResourceHandle) resPtr;
- strcpy((char *)ehResponse.resourceUri,
- (const char *)resourceObserver->resUri);
+ OICStrcpy(ehResponse.resourceUri, sizeof(ehResponse.resourceUri),
+ resourceObserver->resUri);
result = OCDoResponse(&ehResponse);
}
}
FindAndDeleteServerRequest(request);
continue;
}
- strncpy(ehResponse.payload, notificationJSONPayload, MAX_RESPONSE_LENGTH-1);
- ehResponse.payload[MAX_RESPONSE_LENGTH] = '\0';
+ OICStrcpy(ehResponse.payload, MAX_RESPONSE_LENGTH + 1,
+ notificationJSONPayload);
ehResponse.payloadSize = strlen(ehResponse.payload) + 1;
ehResponse.persistentBufferFlag = 0;
ehResponse.requestHandle = (OCRequestHandle) request;
{
obsNode->observeId = obsId;
- obsNode->resUri = (char *)OICMalloc(strlen(resUri)+1);
+ obsNode->resUri = OICStrdup(resUri);
VERIFY_NON_NULL (obsNode->resUri);
- memcpy (obsNode->resUri, resUri, strlen(resUri)+1);
obsNode->qos = qos;
if(query)
{
- obsNode->query = (char *)OICMalloc(strlen(query)+1);
+ obsNode->query = OICStrdup(query);
VERIFY_NON_NULL (obsNode->query);
- memcpy (obsNode->query, query, strlen(query)+1);
}
// If tokenLength is zero, the return value depends on the
// particular library implementation (it may or may not be a null pointer).
*observationOption = options[i].optionData[0];
for(uint8_t c = i; c < *numOptions-1; c++)
{
- options[i].protocolID = options[i+1].protocolID;
- options[i].optionID = options[i+1].optionID;
- options[i].optionLength = options[i+1].optionLength;
- memcpy(options[i].optionData, options[i+1].optionData, options[i+1].optionLength);
+ options[i] = options[i+1];
}
(*numOptions)--;
return OC_STACK_OK;
#include "ocobserve.h"
#include "occollection.h"
#include "oic_malloc.h"
+#include "oic_string.h"
#include "logger.h"
#include "cJSON.h"
jsonLen = strlen(jsonStr);
if (jsonLen < *remaining)
{
- strcpy(out, jsonStr);
+ OICStrcpy(out, *remaining, jsonStr);
*remaining = *remaining - jsonLen;
}
else
if (jsonLen < *remaining)
{
- strncpy(out, jsonStr, (jsonLen + 1));
+ OICStrcpy(out, *remaining, jsonStr);
*remaining = *remaining - jsonLen;
ret = OC_STACK_OK;
}
if (jsonLen < *remaining)
{
- strncpy(out, jsonStr, (jsonLen + 1));
+ OICStrcpy(out, *remaining, jsonStr);
*remaining = *remaining - jsonLen;
ret = OC_STACK_OK;
}
static OCStackResult DeepCopyPlatFormInfo(OCPlatformInfo info)
{
- OCStackResult ret = OC_STACK_OK;
- ret = CloneStringIfNonNull(&(savedPlatformInfo.platformID), info.platformID);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
-
- ret = CloneStringIfNonNull(&(savedPlatformInfo.manufacturerName), info.manufacturerName);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
-
- ret = CloneStringIfNonNull(&(savedPlatformInfo.manufacturerUrl), info.manufacturerUrl);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
-
- ret = CloneStringIfNonNull(&(savedPlatformInfo.modelNumber), info.modelNumber);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
-
- ret = CloneStringIfNonNull(&(savedPlatformInfo.dateOfManufacture), info.dateOfManufacture);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
-
- ret = CloneStringIfNonNull(&(savedPlatformInfo.platformVersion), info.platformVersion);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
-
- ret = CloneStringIfNonNull(&(savedPlatformInfo.operatingSystemVersion), info.operatingSystemVersion);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
-
- ret = CloneStringIfNonNull(&(savedPlatformInfo.hardwareVersion), info.hardwareVersion);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
-
- ret = CloneStringIfNonNull(&(savedPlatformInfo.firmwareVersion), info.firmwareVersion);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
-
- ret = CloneStringIfNonNull(&(savedPlatformInfo.supportUrl), info.supportUrl);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
-
- ret = CloneStringIfNonNull(&(savedPlatformInfo.systemTime), info.systemTime);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
+ savedPlatformInfo.platformID = OICStrdup(info.platformID);
+ savedPlatformInfo.manufacturerName = OICStrdup(info.manufacturerName);
+ savedPlatformInfo.manufacturerUrl = OICStrdup(info.manufacturerUrl);
+ savedPlatformInfo.modelNumber = OICStrdup(info.modelNumber);
+ savedPlatformInfo.dateOfManufacture = OICStrdup(info.dateOfManufacture);
+ savedPlatformInfo.platformVersion = OICStrdup(info.platformVersion);
+ savedPlatformInfo.operatingSystemVersion = OICStrdup(info.operatingSystemVersion);
+ savedPlatformInfo.hardwareVersion = OICStrdup(info.hardwareVersion);
+ savedPlatformInfo.firmwareVersion = OICStrdup(info.firmwareVersion);
+ savedPlatformInfo.supportUrl = OICStrdup(info.supportUrl);
+ savedPlatformInfo.systemTime = OICStrdup(info.systemTime);
+
+ if ((!savedPlatformInfo.platformID && info.platformID)||
+ (!savedPlatformInfo.manufacturerName && info.manufacturerName)||
+ (!savedPlatformInfo.manufacturerUrl && info.manufacturerUrl)||
+ (!savedPlatformInfo.modelNumber && info.modelNumber)||
+ (!savedPlatformInfo.dateOfManufacture && info.dateOfManufacture)||
+ (!savedPlatformInfo.platformVersion && info.platformVersion)||
+ (!savedPlatformInfo.operatingSystemVersion && info.operatingSystemVersion)||
+ (!savedPlatformInfo.hardwareVersion && info.hardwareVersion)||
+ (!savedPlatformInfo.firmwareVersion && info.firmwareVersion)||
+ (!savedPlatformInfo.supportUrl && info.supportUrl)||
+ (!savedPlatformInfo.systemTime && info.systemTime))
+ {
+ DeletePlatformInfo();
+ return OC_STACK_INVALID_PARAM;
+ }
return OC_STACK_OK;
- exit:
- DeletePlatformInfo();
- return ret;
-
}
OCStackResult SavePlatformInfo(OCPlatformInfo info)
static OCStackResult DeepCopyDeviceInfo(OCDeviceInfo info)
{
- OCStackResult ret = OC_STACK_OK;
+ savedDeviceInfo.deviceName = OICStrdup(info.deviceName);
- ret = CloneStringIfNonNull(&(savedDeviceInfo.deviceName), info.deviceName);
- VERIFY_SUCCESS(ret, OC_STACK_OK);
+ if(!savedDeviceInfo.deviceName && info.deviceName)
+ {
+ DeleteDeviceInfo();
+ return OC_STACK_NO_MEMORY;
+ }
return OC_STACK_OK;
-
- exit:
- DeleteDeviceInfo();
- return ret;
}
OCStackResult SaveDeviceInfo(OCDeviceInfo info)
#include "ocserverrequest.h"
#include "ocresourcehandler.h"
#include "oic_malloc.h"
+#include "oic_string.h"
#include "cacommon.h"
#include "cainterface.h"
if(query)
{
- strncpy((char*)serverRequest->query,
- (const char*)query, sizeof(serverRequest->query) - 1);
+ OICStrcpy(serverRequest->query, sizeof(serverRequest->query), query);
}
if(rcvdVendorSpecificHeaderOptions)
}
if(reqJSONPayload && reqTotalSize)
{
- // destination is at least 1 greater than the source, so a NULL always exists in the
- // last character
- strncpy((char*)serverRequest->reqJSONPayload,
- (const char*)reqJSONPayload, reqTotalSize - 1);
+ OICStrcpy(serverRequest->reqJSONPayload, reqTotalSize, reqJSONPayload);
}
serverRequest->requestComplete = 0;
if(requestToken)
if(resourceUrl)
{
- strncpy((char*)serverRequest->resourceUrl,
- (const char*)resourceUrl, sizeof(serverRequest->resourceUrl) - 1);
+ OICStrcpy(serverRequest->resourceUrl, sizeof(serverRequest->resourceUrl),
+ resourceUrl);
}
if (addressInfo)
/**
* Form the OCEntityHandlerRequest struct that is passed to a resource's entity handler
*
- * @param entityHandlerRequest - pointer to the OCEntityHandlerRequest struct that is created
+ * @param entityHandlerRequest - pointer to the OCEntityHandlerRequest struct that is created.
+ * Required to be zero-initialized before calling this function.
* @param request - request handle
* @param method - RESTful method
* @param resource - resource handle
{
if (entityHandlerRequest)
{
- memset(entityHandlerRequest, 0, sizeof(OCEntityHandlerRequest));
+ entityHandlerRequest->resource = (OCResourceHandle) resource;
entityHandlerRequest->requestHandle = request;
entityHandlerRequest->method = method;
- entityHandlerRequest->resource = (OCResourceHandle) resource;
entityHandlerRequest->query = queryBuf;
- entityHandlerRequest->reqJSONPayload = bufReqPayload;
+ entityHandlerRequest->obsInfo.action = observeAction;
+ entityHandlerRequest->obsInfo.obsId = observeID;
entityHandlerRequest->numRcvdVendorSpecificHeaderOptions = numVendorOptions;
entityHandlerRequest->rcvdVendorSpecificHeaderOptions = vendorOptions;
+ entityHandlerRequest->reqJSONPayload = bufReqPayload;
- entityHandlerRequest->obsInfo.action = observeAction;
- entityHandlerRequest->obsInfo.obsId = observeID;
return OC_STACK_OK;
}
char payload[MAX_RESPONSE_LENGTH + OC_JSON_PREFIX_LEN + OC_JSON_SUFFIX_LEN + 1] = {};
// Put the JSON prefix and suffix around the payload
- strcpy(payload, (const char *)OC_JSON_PREFIX);
+ OICStrcpy(payload, sizeof(payload), OC_JSON_PREFIX);
if(ehResponse->payloadSize)
{
- strncat(payload, (const char *)ehResponse->payload,
- ehResponse->payloadSize < MAX_RESPONSE_LENGTH ?
- ehResponse->payloadSize : MAX_RESPONSE_LENGTH);
+ OICStrcatPartial(payload, sizeof(payload),
+ ehResponse->payload,
+ ehResponse->payloadSize < MAX_RESPONSE_LENGTH ?
+ ehResponse->payloadSize : MAX_RESPONSE_LENGTH);
}
- strcat(payload, (const char *)OC_JSON_SUFFIX);
+ OICStrcat(payload, sizeof(payload), OC_JSON_SUFFIX);
responseInfo.info.payload = (CAPayload_t)payload;
#ifdef WITH_PRESENCE
{
OC_LOG(ERROR, TAG, PCF("There is room in response buffer"));
// append
- strncat((char *)serverResponse->payload,
- (char *)ehResponse->payload,
+ // allocated size of the payload is assumed, since a search of the code
+ // shows that it is OICCalloc'ed to this size in AddServerResponse above
+ OICStrcatPartial(serverResponse->payload,
+ MAX_RESPONSE_LENGTH,
+ ehResponse->payload,
serverResponse->remainingPayloadSize);
OC_LOG_V(INFO, TAG, "Current aggregated response ...%s", serverResponse->payload);
serverResponse->remainingPayloadSize -= strlen((char *)ehResponse->payload);
else
{
OC_LOG(INFO, TAG, PCF("More response fragments to come"));
- strncat((char *)serverResponse->payload,
+ OICStrcatPartial(serverResponse->payload,
+ MAX_RESPONSE_LENGTH,
OC_JSON_SEPARATOR_STR,
serverResponse->remainingPayloadSize);
OC_LOG_V(INFO, TAG, "Current aggregated response ...%s", serverResponse->payload);
#include "ocobserve.h"
#include "ocrandom.h"
#include "oic_malloc.h"
+#include "oic_string.h"
#include "ocserverrequest.h"
#include "secureresourcemanager.h"
#include "cacommon.h"
return UINT32_MAX;
}
}
-/**
- * Clones a string IFF its pointer value is not NULL.
- *
- * Note: The caller to this function is responsible for calling @ref OICFree
- * for the destination parameter.
- *
- * @param dest The destination string for the string value to be cloned.
- *
- * @param src The source for the string value to be to cloned.
- */
-OCStackResult CloneStringIfNonNull(char **dest, const char *src)
-{
- if (src)
- {
- *dest = (char*) OICMalloc(strlen(src) + 1);
- if (!*dest)
- {
- return OC_STACK_NO_MEMORY;
- }
- strcpy(*dest, src);
- }
- else
- {
- *dest = NULL;
- }
- return OC_STACK_OK;
-}
OCStackResult OCBuildIPv4Address(uint8_t a, uint8_t b, uint8_t c, uint8_t d,
uint16_t port, OCDevAddr *ipAddr)
OCStackResult ret = OC_STACK_ERROR;
char * tok = NULL;
char * savePtr = NULL;
- char * cpAddress = (char *) OICMalloc(strlen(endPoint->addressInfo.IP.ipAddress) + 1);
+ char* cpAddress = OICStrdup(endPoint->addressInfo.IP.ipAddress);
if(!cpAddress)
{
ret = OC_STACK_NO_MEMORY;
goto exit;
}
- memcpy(cpAddress, endPoint->addressInfo.IP.ipAddress,
- strlen(endPoint->addressInfo.IP.ipAddress) + 1);
// Grabs the first three numbers from the IPv4 address and replaces dots
for(int i=0; i<4; i++)
cJSON *maxAgeObj = NULL;
cJSON *triggerObj = NULL;
cJSON *resObj = NULL;
- size_t size = 0;
if(repObj)
{
ocObj = cJSON_GetObjectItem(repObj, OC_RSRVD_OC);
OC_RSRVD_RESOURCE_TYPE);
if(resObj)
{
- size = strlen(resObj->valuestring) + 1;
- *resType = (char *)OICMalloc(size);
+ *resType = OICStrdup(resObj->valuestring);
if(!*resType)
{
goto exit;
}
- strncpy(*resType, resObj->valuestring, size);
}
else
{
char *ipAddress = NULL;
int presenceSubscribe = 0;
int multicastPresenceSubscribe = 0;
- size_t addressLen = 0;
if (responseInfo->result != CA_SUCCESS)
{
goto exit;
}
- addressLen = strlen(endPoint->addressInfo.IP.ipAddress);
- ipAddress = (char *) OICMalloc(addressLen + 1);
+ ipAddress = OICStrdup(endPoint->addressInfo.IP.ipAddress);
if(!ipAddress)
{
goto exit;
}
- strncpy(ipAddress, endPoint->addressInfo.IP.ipAddress, addressLen);
- ipAddress[addressLen] = '\0';
snprintf(fullUri, MAX_URI_LENGTH, "coap://%s:%u%s", ipAddress, endPoint->addressInfo.IP.port,
OC_PRESENCE_URI);
}
else
{
- uint32_t uriLen = strlen(fullUri);
- char* uri = (char *) OICMalloc(uriLen + 1);
- if(uri)
- {
- memcpy(uri, fullUri, (uriLen + 1));
- }
- else
+ char* uri = OICStrdup(fullUri);
+ if(!uri)
{
OC_LOG(ERROR, TAG,
PCF("No Memory for URI to store in the presence node"));
if(strlen(newUri) < MAX_URI_LENGTH)
{
//copy URI
- memcpy (&(serverRequest.resourceUrl), newUri, strlen(newUri));
+ OICStrcpy(serverRequest.resourceUrl, sizeof(serverRequest.resourceUrl),
+ newUri);
OICFree(newUri);
}
else
{
if(strlen(query) < MAX_QUERY_LENGTH)
{
- memcpy (&(serverRequest.query), query, strlen(query));
+ OICStrcpy(serverRequest.query, sizeof(serverRequest.query), query);
OICFree(query);
}
else
{
size_t payloadLen = strlen(requestInfo->info.payload);
serverRequest.reqTotalSize = payloadLen + 1;
- memcpy (&(serverRequest.reqJSONPayload), requestInfo->info.payload,
- payloadLen);
+ OICStrcpy(serverRequest.reqJSONPayload, sizeof(serverRequest.reqJSONPayload),
+ requestInfo->info.payload);
}
else
{
requestUri = (char *) OICMalloc(uriLen + 1);
if(requestUri)
{
- memcpy(requestUri, newUri, (uriLen + 1));
+ OICStrcpy(requestUri, uriLen + 1, newUri);
}
else
{
CADestroyToken(token);
goto exit;
}
- strncpy(grpEnd.resourceUri, requiredUri, (uriLen + 1));
+ OICStrcpy(grpEnd.resourceUri, uriLen +1, requiredUri);
caResult = CASendRequestToAll(&grpEnd, &requestInfo);
}
presenceState = OC_PRESENCE_INITIALIZED;
CAAddress_t addressInfo;
- strncpy(addressInfo.IP.ipAddress, OC_MULTICAST_IP, CA_IPADDR_SIZE);
+ OICStrcpy(addressInfo.IP.ipAddress, sizeof(addressInfo.IP.ipAddress),
+ OC_MULTICAST_IP);
addressInfo.IP.port = OC_MULTICAST_PORT;
CAToken_t caToken = NULL;
OCResource *pointer = NULL;
char *str = NULL;
- size_t size = 0;
OCStackResult result = OC_STACK_ERROR;
OC_LOG(INFO, TAG, PCF("Entering OCCreateResource"));
insertResource(pointer);
// Set the uri
- size = strlen(uri) + 1;
- str = (char *) OICMalloc(size);
+ str = OICStrdup(uri);
if (!str)
{
result = OC_STACK_NO_MEMORY;
goto exit;
}
- strncpy(str, uri, size);
pointer->uri = str;
// Set properties. Set OC_ACTIVE
{
OCResourceType *pointer = NULL;
char *str = NULL;
- size_t size = 0;
OCStackResult result = OC_STACK_ERROR;
OC_LOG(INFO, TAG, PCF("Entering BindResourceTypeToResource"));
}
// Set the resourceTypeName
- size = strlen(resourceTypeName) + 1;
- str = (char *) OICMalloc(size);
+ str = OICStrdup(resourceTypeName);
if (!str)
{
result = OC_STACK_NO_MEMORY;
goto exit;
}
- strncpy(str, resourceTypeName, size);
pointer->resourcetypename = str;
insertResourceType(resource, pointer);
{
OCResourceInterface *pointer = NULL;
char *str = NULL;
- size_t size = 0;
OCStackResult result = OC_STACK_ERROR;
OC_LOG(INFO, TAG, PCF("Entering BindResourceInterfaceToResource"));
}
// Set the resourceinterface name
- size = strlen(resourceInterfaceName) + 1;
- str = (char *) OICMalloc(size);
+ str = OICStrdup(resourceInterfaceName);
if (!str)
{
result = OC_STACK_NO_MEMORY;
goto exit;
}
- strncpy(str, resourceInterfaceName, size);
pointer->name = str;
// Bind the resourceinterface to the resource
if(strncmp(query, "rt=", 3) == 0)
{
- *resourceType = (char *) OICMalloc(strlen(query)-3 + 1);
+ *resourceType = OICStrdup(&query[3]);
if(!*resourceType)
{
result = OC_STACK_NO_MEMORY;
}
else
{
- strcpy((char *)*resourceType, ((const char *)&query[3]));
result = OC_STACK_OK;
}
}
{
goto exit;
}
- strncpy(*uriWithoutQuery, uri, uriWithoutQueryLen);
+ OICStrcpy(*uriWithoutQuery, uriWithoutQueryLen +1, uri);
}
else
{
*uriWithoutQuery = NULL;
goto exit;
}
- strncpy(*query, pointerToDelimiter + 1, queryLen);
+ OICStrcpy(*query, queryLen + 1, pointerToDelimiter + 1);
}
return OC_STACK_OK;
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "oc_logger.h"
+#include "oic_string.h"
#include <string.h>
#include <stdlib.h>
int oc_log_set_module(oc_log_ctx_t *ctx, const char *module_name)
{
char *mn = NULL;
- size_t len = 0;
if(!ctx || !module_name)
{
}
/* Swap pointers so that module data's not erased in the event of failure: */
- len = strlen(module_name);
-
- mn = (char *)malloc(1 + len);
+ mn = OICStrdup(module_name);
if(!mn)
{
return 0;
}
- memcpy(mn, module_name, 1 + len);
-
if(!ctx->module_name)
{
free(ctx->module_name);
it->getOptionID(),
it->getOptionData().length() + 1,
reinterpret_cast<const uint8_t*>(it->getOptionData().c_str()));
- //options[i].protocolID = OC_COAP_ID;
- //options[i].optionID = static_cast<uint16_t>(it->getOptionID());
- //options[i].optionLength = (it->getOptionData()).length() + 1;
- //memcpy(options[i].optionData, (it->getOptionData()).c_str(),
- // (it->getOptionData()).length() + 1);
i++;
}
else
{
OCEntityHandlerResponse response;
- std::string payLoad;
- HeaderOptions serverHeaderOptions;
-
- payLoad = pResponse->getPayload();
- serverHeaderOptions = pResponse->getHeaderOptions();
+ std::string payLoad = pResponse->getPayload();
+ HeaderOptions serverHeaderOptions = pResponse->getHeaderOptions();
response.requestHandle = pResponse->getRequestHandle();
response.resourceHandle = pResponse->getResourceHandle();
throw OCException(OC::Exception::NO_MEMORY, OC_STACK_NO_MEMORY);
}
- strncpy(response.payload, payLoad.c_str(), payLoad.length()+1);
+ payLoad.copy(response.payload, payLoad.length());
+ response.payload[payLoad.length()] = '\0';
response.payloadSize = payLoad.length() + 1;
response.persistentBufferFlag = 0;
static_cast<uint16_t>(it->getOptionID());
response.sendVendorSpecificHeaderOptions[i].optionLength =
(it->getOptionData()).length() + 1;
- memcpy(response.sendVendorSpecificHeaderOptions[i].optionData,
- (it->getOptionData()).c_str(),
- (it->getOptionData()).length() + 1);
+ std::copy(it->getOptionData().begin(),
+ it->getOptionData().end(),
+ response.sendVendorSpecificHeaderOptions[i].optionData);
+ response.sendVendorSpecificHeaderOptions[i].optionData[it->getOptionData().length()]
+ = '\0';
i++;
}
if(OC_EH_RESOURCE_CREATED == response.ehResult)
{
- std::string createdUri = pResponse->getNewResourceUri();
- strncpy(reinterpret_cast<char*>(response.resourceUri),
- createdUri.c_str(),
- createdUri.length() + 1);
+ pResponse->getNewResourceUri().copy(response.resourceUri,
+ sizeof (response.resourceUri) - 1);
+ response.resourceUri[pResponse->getNewResourceUri().length()] = '\0';
}
if(cLock)