Open dhoverml opened 2 months ago
If this can happen in multiple places throughout the codebase then it'd be good to have a formal definition of the resizing algorithm:
template<size_t ElementSize, size_t UpperLimit, bool PreferPow2, class OtherArgs...>
constexpr size_t calculate_new_capacity(size_t p_current_size, size_t p_new_size);
Something like that, anyway.
It's not necessarily possible as different containers use different methods for memory management
Tested versions
master (b75f0485ba15951b87f1d9a2d8dd0fcd55e178e4)
System information
Ubuntu 20.04 LTS
Issue description
LocalVector
with size > 0x80000000, with a non-trivially-constructible type, crashes.LocalVector
with size > 0x80000000, with a trivially-constructible type, silently does not crash when indexed despite capacity == 0.One potential fix is to change the code here: https://github.com/godotengine/godot/blob/master/core/templates/local_vector.h#L159-L163
From:
To:
This will need to be done in other functions in
LocalVector
, as well as look over other places that usenearest_power_of_2_templated
(and similar functions) in case they don't handle zero.Steps to reproduce
Add this somewhere that is guaranteed to be executed when launching the app/editor:
Compile and run:
Output:
Trivially constructible types can result in undefined behavior or crash:
Output
Minimal reproduction project (MRP)
N/A