diff options
| author | 2019-05-19 00:27:43 +0200 | |
|---|---|---|
| committer | 2019-05-19 00:27:43 +0200 | |
| commit | 23e5a7636bba1565d000adcd4c3debc0788398c5 (patch) | |
| tree | 4b3d51f3e0cfd34a3ea0b21ac87bfc788e3f0022 | |
| parent | 08c6143b870167ad29f9c20a298e0f75c986d0ea (diff) | |
| download | libplist-23e5a7636bba1565d000adcd4c3debc0788398c5.tar.gz libplist-23e5a7636bba1565d000adcd4c3debc0788398c5.tar.bz2 | |
plist_array_get_item_index(): return UINT_MAX instead of 0 when node can't be found
| -rw-r--r-- | include/plist/plist.h | 2 | ||||
| -rw-r--r-- | src/Array.cpp | 4 | ||||
| -rw-r--r-- | src/plist.c | 2 |
3 files changed, 6 insertions, 2 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h index 263efa8..63e9d84 100644 --- a/include/plist/plist.h +++ b/include/plist/plist.h | |||
| @@ -247,7 +247,7 @@ extern "C" | |||
| 247 | * Get the index of an item. item must be a member of a #PLIST_ARRAY node. | 247 | * Get the index of an item. item must be a member of a #PLIST_ARRAY node. |
| 248 | * | 248 | * |
| 249 | * @param node the node | 249 | * @param node the node |
| 250 | * @return the node index | 250 | * @return the node index or UINT_MAX if node index can't be determined |
| 251 | */ | 251 | */ |
| 252 | uint32_t plist_array_get_item_index(plist_t node); | 252 | uint32_t plist_array_get_item_index(plist_t node); |
| 253 | 253 | ||
diff --git a/src/Array.cpp b/src/Array.cpp index a511841..d5d9d7c 100644 --- a/src/Array.cpp +++ b/src/Array.cpp | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | #include <plist/Array.h> | 22 | #include <plist/Array.h> |
| 23 | 23 | ||
| 24 | #include <algorithm> | 24 | #include <algorithm> |
| 25 | #include <limits.h> | ||
| 25 | 26 | ||
| 26 | namespace PList | 27 | namespace PList |
| 27 | { | 28 | { |
| @@ -118,6 +119,9 @@ void Array::Remove(Node* node) | |||
| 118 | if (node) | 119 | if (node) |
| 119 | { | 120 | { |
| 120 | uint32_t pos = plist_array_get_item_index(node->GetPlist()); | 121 | uint32_t pos = plist_array_get_item_index(node->GetPlist()); |
| 122 | if (pos == UINT_MAX) { | ||
| 123 | return; | ||
| 124 | } | ||
| 121 | plist_array_remove_item(_node, pos); | 125 | plist_array_remove_item(_node, pos); |
| 122 | std::vector<Node*>::iterator it = _array.begin(); | 126 | std::vector<Node*>::iterator it = _array.begin(); |
| 123 | it += pos; | 127 | it += pos; |
diff --git a/src/plist.c b/src/plist.c index f22a8a0..3ffedc4 100644 --- a/src/plist.c +++ b/src/plist.c | |||
| @@ -430,7 +430,7 @@ PLIST_API uint32_t plist_array_get_item_index(plist_t node) | |||
| 430 | { | 430 | { |
| 431 | return node_child_position(father, node); | 431 | return node_child_position(father, node); |
| 432 | } | 432 | } |
| 433 | return 0; | 433 | return UINT_MAX; |
| 434 | } | 434 | } |
| 435 | 435 | ||
| 436 | static void _plist_array_post_insert(plist_t node, plist_t item, long n) | 436 | static void _plist_array_post_insert(plist_t node, plist_t item, long n) |
