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(); }