From 3c85ad77664f6ec1d50d9aebbd2d2f21adae0e21 Mon Sep 17 00:00:00 2001 From: Dmitri Mokhov Date: Tue, 28 Jan 2025 06:26:53 -0800 Subject: [PATCH] Fix UBSan issue (#1615) Signed-off-by: Dmitri Mokhov --- include/oneapi/tbb/concurrent_hash_map.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/oneapi/tbb/concurrent_hash_map.h b/include/oneapi/tbb/concurrent_hash_map.h index b30033742c..0c52b72555 100644 --- a/include/oneapi/tbb/concurrent_hash_map.h +++ b/include/oneapi/tbb/concurrent_hash_map.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005-2022 Intel Corporation + Copyright (c) 2005-2025 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -467,9 +467,13 @@ class hash_map_iterator { friend class concurrent_hash_map; hash_map_iterator( const Container &map, std::size_t index, const bucket *b, node_base *n ) : - my_map(&map), my_index(index), my_bucket(b), my_node(static_cast(n)) + my_map(&map), my_index(index), my_bucket(b), my_node(nullptr) { - if( b && !map_base::is_valid(n) ) + // Cannot directly initialize to n, because it could be an invalid node pointer (e.g., when + // setting a midpoint for a 1-element range). If it is, try one from a subsequent bucket. + if( map_base::is_valid(n) ) + my_node = static_cast(n); + else if( b ) advance_to_next_bucket(); }