Skip to content

Commit

Permalink
Fixing the negative scenarios in ut_kvp_getStringField() #42
Browse files Browse the repository at this point in the history
  • Loading branch information
kanjoe24 committed Sep 17, 2024
1 parent 358f99c commit b906244
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "${workspaceFolder}/tests/bin/",
"program": "${workspaceFolder}/tests/bin/ut_control_test",
"environment": [ {"name": "LD_LIBRARY_PATH", "value":"${workspaceFolder}/tests/bin/"} ],
"cwd": "${workspaceFolder}/tests/build/bin/",
"program": "${workspaceFolder}/tests/build/bin/ut_control_test",
"environment": [ {"name": "LD_LIBRARY_PATH", "value":"${workspaceFolder}/tests/build/bin/"} ],
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
Expand Down
16 changes: 9 additions & 7 deletions src/ut_kvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,14 +597,16 @@ uint32_t ut_kvp_getListCount( ut_kvp_instance_t *pInstance, const char *pszKey)
return 0;
}

if (fy_node_is_sequence(node))
if (!fy_node_is_sequence(node))
{
count = fy_node_sequence_item_count(node);
if (count == -1)
{
UT_LOG_ERROR("fy_node_sequence_item_count() returned error\n ");
return 0;
}
return 0; // Early return on negative check
}

count = fy_node_sequence_item_count(node);
if (count == -1)
{
UT_LOG_ERROR("fy_node_sequence_item_count() returned error\n");
return 0;
}

return count;
Expand Down
3 changes: 3 additions & 0 deletions tests/src/ut_test_kvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ void test_ut_kvp_list(void)
uint32_t result;
int count;

count = ut_kvp_getListCount(gpMainTestInstance, "decodeTest/checkFloat");
UT_ASSERT( count == 0 );

count = ut_kvp_getListCount(gpMainTestInstance, "decodeTest/checkStringList");
UT_ASSERT( count == 3 );

Expand Down

0 comments on commit b906244

Please sign in to comment.