Skip to content

Commit 3c85ad7

Browse files
authored
Fix UBSan issue (#1615)
Signed-off-by: Dmitri Mokhov <[email protected]>
1 parent 9d45787 commit 3c85ad7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

include/oneapi/tbb/concurrent_hash_map.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2022 Intel Corporation
2+
Copyright (c) 2005-2025 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -467,9 +467,13 @@ class hash_map_iterator {
467467
friend class concurrent_hash_map;
468468

469469
hash_map_iterator( const Container &map, std::size_t index, const bucket *b, node_base *n ) :
470-
my_map(&map), my_index(index), my_bucket(b), my_node(static_cast<node*>(n))
470+
my_map(&map), my_index(index), my_bucket(b), my_node(nullptr)
471471
{
472-
if( b && !map_base::is_valid(n) )
472+
// Cannot directly initialize to n, because it could be an invalid node pointer (e.g., when
473+
// setting a midpoint for a 1-element range). If it is, try one from a subsequent bucket.
474+
if( map_base::is_valid(n) )
475+
my_node = static_cast<node*>(n);
476+
else if( b )
473477
advance_to_next_bucket();
474478
}
475479

0 commit comments

Comments
 (0)