libimobiledevice / libplist

A library to handle Apple Property List format in binary or XML
https://libimobiledevice.org
GNU Lesser General Public License v2.1
535 stars 304 forks source link

plist_array_get_item_index return 0 ? #129

Closed xdeng closed 5 years ago

xdeng commented 5 years ago
PLIST_API uint32_t plist_array_get_item_index(plist_t node)
{
    plist_t father = plist_get_parent(node);
    if (PLIST_ARRAY == plist_get_node_type(father))
    {
        return node_child_position(father, node);
    }
    return 0;
}

return 0; 0 Is a valid value

/**
 * Remove an existing position in a #PLIST_ARRAY node.
 * Removed position will be freed using #plist_free.
 *
 * @param node the node of type #PLIST_ARRAY
 * @param n The position to remove. Range is [0, array_size[. Assert if n is not in range.
 */
void plist_array_remove_item(plist_t node, uint32_t n);
xdeng commented 5 years ago

I know that the probability of not being an array is very low. But the probability that the number of arrays is greater than 0 is very high

nikias commented 5 years ago

This function is basically only used by the C++ implementation. I changed the function to return UINT_MAX (0xFFFFFFFF) if the node index can't be determined. See commit 23e5a7636bba1565d000adcd4c3debc0788398c5.