Open alsliahona opened 3 years ago
Note that this was tested by simply constructing a string using a custom allocator that returns nullptr. Construction was like this: using mockwstring = eastl::basic_string<wchar_t, MockAllocator>; mockwstring wstrMockTest(L"This is a test!"); if (false == wstrMockTest.validate()) ...Handle out-of-memory condition <-- This line is never reached
If an allocator returns nullptr, basic_string's constructor still attempts to copy to nullptr. NOTE: I only tested string, nothing else, the problem may be more wide-spread.
Instead of blindly copying data to a pointer returned by the allocator, there should be a check to ensure that the allocator did not return nullptr. Similarly the size/length of the container should not be adjusted until after verification that the allocation worked.
Where exceptions are supported an exception should be thrown on allocation failure. Where they are not, the object should become invalid, so that the validate() call after the constructor returns false.