pdr: pldm_entity_get_num_children(): Return zero for invalid arguments
It's not possible to return a sensible value if the arguments are
invalid. Return zero as there are no children to match if a NULL node is
passed, and similarly, no matching nodes if the assocation type doesn't
meet the requirements.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ia0edf397a01a1652992a258f80e9836a57209d2d
diff --git a/src/pdr.c b/src/pdr.c
index 3c9db5d..7bf0f67 100644
--- a/src/pdr.c
+++ b/src/pdr.c
@@ -742,8 +742,16 @@
uint8_t association_type)
{
assert(node != NULL);
+ if (!node) {
+ return 0;
+ }
+
assert(association_type == PLDM_ENTITY_ASSOCIAION_PHYSICAL ||
association_type == PLDM_ENTITY_ASSOCIAION_LOGICAL);
+ if (!(association_type == PLDM_ENTITY_ASSOCIAION_PHYSICAL ||
+ association_type == PLDM_ENTITY_ASSOCIAION_LOGICAL)) {
+ return 0;
+ }
size_t count = 0;
pldm_entity_node *curr = node->first_child;