diff options
author | Arve Hjønnevåg <arve@android.com> | 2024-04-17 16:26:32 -0700 |
---|---|---|
committer | Arve Hjønnevåg <arve@android.com> | 2024-04-17 16:41:38 -0700 |
commit | 7306e3dd6f764ff28338880cc573bc6069c8848a (patch) | |
tree | 6f7c049ec1135e30452b6d046389bd69f87b2ab4 | |
parent | fdc0761fd04f1c388bdcb99dd6d38dda050ad24d (diff) | |
download | common-7306e3dd6f764ff28338880cc573bc6069c8848a.tar.gz |
binary_search_tree: Add missing type check for bst_search_type
The caller passed an item to bst_search_type that did not match the
specified type without getting a compile error as long as item also had
a member with the same name. As a result the compare function would get
a pointer passed to an object with the wrong type.
Bug: 335515844
Change-Id: I85695b8aaf4463a117de1f3a9a9b0f9acb72ada1
-rw-r--r-- | lib/binary_search_tree/include/lib/binary_search_tree.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/binary_search_tree/include/lib/binary_search_tree.h b/lib/binary_search_tree/include/lib/binary_search_tree.h index 217a900b..e9cd1a01 100644 --- a/lib/binary_search_tree/include/lib/binary_search_tree.h +++ b/lib/binary_search_tree/include/lib/binary_search_tree.h @@ -163,9 +163,11 @@ static inline struct bst_node *bst_search_key(const struct bst_root *root, * * Return: Item in @root matching @item, or %NULL if no matching node is found. */ -#define bst_search_type(root, item, compare, type, member) \ - containerof_null_safe(bst_search(root, &(item)->member, compare), type, \ - member) +#define bst_search_type(root, item, compare, type, member) ({ \ + type *__item = (item); \ + containerof_null_safe(bst_search(root, &__item->member, compare), type, \ + member); \ +}) /** * bst_search_key_type - Find an item in a binary search tree. |