Skip to content

Commit c1dcd80

Browse files
committed
add hashmap check
1 parent c1c21a8 commit c1dcd80

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"cmake.configureArgs": [
3-
// "-DSANITIZER:BOOL=ON"
3+
//"-DSANITIZER:BOOL=ON"
44
]
55
}

interface/core/containers/hashset.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,20 +1880,33 @@ namespace hud
18801880

18811881
constexpr usize allocate_control_and_slot(usize max_slot_count) noexcept
18821882
{
1883+
/**
1884+
* Allocation layout is :
1885+
*
1886+
* | aligned_control_size | slots_size |
1887+
* | control_size | |
1888+
* | controls | slot padding | slots |
1889+
* ^ ^
1890+
* control_ptr_ slot_ptr_
1891+
*
1892+
*/
1893+
18831894
const usize control_size {control_size_for_max_count(max_slot_count)};
1884-
const usize slot_size {max_slot_count * sizeof(slot_type)};
1895+
const usize slots_size {max_slot_count * sizeof(slot_type)};
18851896
const uptr aligned_control_size {hud::memory::align_address(control_size, sizeof(slot_type))};
18861897

18871898
if (hud::is_constant_evaluated())
18881899
{
18891900
control_ptr_ = allocator_.template allocate<control_type>(aligned_control_size).data();
1890-
slot_ptr_ = allocator_.template allocate<slot_type>(slot_size).data();
1901+
slot_ptr_ = allocator_.template allocate<slot_type>(slots_size).data();
18911902
}
18921903
else
18931904
{
1894-
const usize aligned_allocation_size {aligned_control_size + slot_size};
1905+
1906+
const usize aligned_allocation_size {aligned_control_size + slots_size};
18951907
control_ptr_ = allocator_.template allocate<control_type>(aligned_allocation_size).data();
1896-
slot_ptr_ = reinterpret_cast<slot_type *>(hud::memory::align_address(reinterpret_cast<const uptr>(control_ptr_ + control_size), alignof(slot_type)));
1908+
slot_ptr_ = reinterpret_cast<slot_type *>(control_ptr_ + aligned_control_size, alignof(slot_type));
1909+
hud::check((u8 *)slot_ptr_ - (u8 *)control_ptr_ == aligned_control_size);
18971910
hud::check(hud::memory::is_pointer_aligned(slot_ptr_, alignof(slot_type)));
18981911
}
18991912
return control_size;
@@ -1904,19 +1917,19 @@ namespace hud
19041917
if (max_slot_count > 0)
19051918
{
19061919
const usize control_size {control_size_for_max_count(max_slot_count)};
1907-
const usize slot_size {max_slot_count * sizeof(slot_type)};
1920+
const usize slots_size {max_slot_count * sizeof(slot_type)};
19081921
const uptr aligned_control_size {hud::memory::align_address(control_size, sizeof(slot_type))};
19091922

19101923
// In a constant-evaluated context, bit_cast cannot be used with pointers
19111924
// and allocation is done in two separate allocation
19121925
if (hud::is_constant_evaluated())
19131926
{
19141927
allocator_.template free<control_type>({control_ptr, aligned_control_size});
1915-
allocator_.template free<slot_type>({slot_ptr, slot_size});
1928+
allocator_.template free<slot_type>({slot_ptr, slots_size});
19161929
}
19171930
else
19181931
{
1919-
const usize aligned_allocation_size {aligned_control_size + slot_size};
1932+
const usize aligned_allocation_size {aligned_control_size + slots_size};
19201933
allocator_.template free<control_type>({control_ptr, aligned_allocation_size});
19211934
}
19221935
}

0 commit comments

Comments
 (0)