diff --git a/api/src/string_array.c b/api/src/string_array.c index 51936dd..47a46e1 100644 --- a/api/src/string_array.c +++ b/api/src/string_array.c @@ -100,7 +100,7 @@ const char * AwaStringArray_GetValueAsCString(const AwaStringArray * array, AwaA if ((nonNulledValue != NULL) && (nulledValue != NULL) && (nonNulledLength >= 0)) { - memcpy(nulledValue, nonNulledValue, nonNulledLength); + memcpy(nulledValue, nonNulledValue, (size_t)nonNulledLength); nulledValue[nonNulledLength] = '\0'; Array_SetValue(nulledStrings, index, nulledValue, nonNulledLength + 1); free(nulledValue); diff --git a/api/src/value.c b/api/src/value.c index 6b1707b..bfb5a75 100644 --- a/api/src/value.c +++ b/api/src/value.c @@ -174,7 +174,7 @@ Value * Value_New(TreeNode rootNode, AwaResourceType type) char * stringValue = Awa_MemAlloc(dataLength + 1); if (stringValue != NULL) { - memcpy(stringValue, dataValue, dataLength); + memcpy(stringValue, dataValue, (size_t)dataLength); stringValue[dataLength] = 0; AwaStringArray_SetValueAsCString((AwaStringArray *)array, index, stringValue); Awa_MemSafeFree(stringValue); diff --git a/core/src/client/lwm2m_client_xml_handlers.c b/core/src/client/lwm2m_client_xml_handlers.c index a4b4665..ab693a8 100644 --- a/core/src/client/lwm2m_client_xml_handlers.c +++ b/core/src/client/lwm2m_client_xml_handlers.c @@ -442,7 +442,7 @@ static int xmlif_RegisterObjectFromXML(Lwm2mContextType * context, TreeNode meta Lwm2mTreeNode * resourceInstanceNode = Lwm2mTreeNode_Create(); Lwm2mTreeNode_AddChild(defaultValueNode, resourceInstanceNode); Lwm2mTreeNode_SetType(resourceInstanceNode, Lwm2mTreeNodeType_ResourceInstance); - Lwm2mTreeNode_SetValue(resourceInstanceNode, defaultValue, defaultValueLength); + Lwm2mTreeNode_SetValue(resourceInstanceNode, defaultValue, (uint16_t)defaultValueLength); Lwm2mTreeNode_SetID(resourceInstanceNode, 0); } else @@ -474,7 +474,7 @@ static int xmlif_RegisterObjectFromXML(Lwm2mContextType * context, TreeNode meta int defaultValueLength = 0; defaultValueLength = xmlif_DecodeValue((char**)&defaultValue, dataType, value, strlen(value)); - if (defaultValueLength != -1) + if (defaultValueLength >= 0) { Lwm2mTreeNode * resourceInstanceNode = Lwm2mTreeNode_Create(); Lwm2mTreeNode_AddChild(defaultValueNode, resourceInstanceNode); diff --git a/lib/xml/xmlparser.c b/lib/xml/xmlparser.c index 12f9a25..58b0e4f 100644 --- a/lib/xml/xmlparser.c +++ b/lib/xml/xmlparser.c @@ -141,7 +141,7 @@ bool charhistoryBuffer_clear(XMLParser_Context xmlParser) char* charhistoryBuffer_lookBack(XMLParser_Context xmlParser, unsigned int count) { char *result = NULL; - if(xmlParser && xmlParser->CharHistoryBuffer && count > 0) { + if(xmlParser && count > 0) { if(xmlParser->HistoryBuffLen >= count) { result = &xmlParser->CharHistoryBuffer[CHARHISTORY_LENGTH-count]; // '-1' because array indexing is 0-based diff --git a/lib/xml/xmltree.c b/lib/xml/xmltree.c index d25e25b..107de94 100644 --- a/lib/xml/xmltree.c +++ b/lib/xml/xmltree.c @@ -354,39 +354,42 @@ TreeNode TreeNode_Navigate(const TreeNode rootNode, const char* path) { // Tokenise path and ensure first pathElement matches char *pathElement = strtok((char*) _path, (const char*) "/"); - if (strcmp((const char*) currentNode->Name, (const char*) pathElement) == 0) + if (pathElement) { - bool childFound = false; - bool pathError = false; - do + if (strcmp((const char*) currentNode->Name, (const char*) pathElement) == 0) { - // Then, get next path-token and find a match for a child node's name - pathElement = strtok(0, "/"); - if (pathElement) + bool childFound = false; + bool pathError = false; + do { - childFound = false; - uint32_t childIndex = 0; - for (childIndex = 0; childIndex < currentNode->ChildCount; childIndex++) + // Then, get next path-token and find a match for a child node's name + pathElement = strtok(0, "/"); + if (pathElement) { - // For each token, check if a child's node name matches the next token in the path - _treeNode thisChild = (_treeNode) currentNode->Children[childIndex]; - if (strcmp((const char*) thisChild->Name, pathElement) == 0) + childFound = false; + uint32_t childIndex = 0; + for (childIndex = 0; childIndex < currentNode->ChildCount; childIndex++) { - currentNode = thisChild; - childFound = true; - break; + // For each token, check if a child's node name matches the next token in the path + _treeNode thisChild = (_treeNode) currentNode->Children[childIndex]; + if (strcmp((const char*) thisChild->Name, pathElement) == 0) + { + currentNode = thisChild; + childFound = true; + break; + } } - } - if (!childFound) - { - currentNode = NULL; - pathError = true; + if (!childFound) + { + currentNode = NULL; + pathError = true; + } } - } - } while(pathElement && !pathError); - if (pathError) - currentNode = NULL; + } while(pathElement && !pathError); + if (pathError) + currentNode = NULL; + } } } Flow_MemFree((void **) &_path); @@ -535,8 +538,7 @@ bool Tree_Delete(TreeNode node) // Move currentNode up to its parent before freeing this node _treeNode tempNode = currentNode; currentNode = (_treeNode) currentNode->Parent; - if (tempNode) - Flow_MemFree((void **) &tempNode); + Flow_MemFree((void **) &tempNode); // Rinse and repeat, now that we're at the new end of the old branch }