Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some coverity issues raised in April 11th scan. #115

Merged
merged 1 commit into from
Apr 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/string_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion api/src/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions core/src/client/lwm2m_client_xml_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/xml/xmlparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 29 additions & 27 deletions lib/xml/xmltree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down