containers: increase_capacity() returns false before asserting when nofail_flag is set

try_resize()/try_reserve() etc. (nofail) are used to fail cleanly on huge
allocations, e.g. the Wuffs LDR loader's pixel and work buffers for a small
crafted file whose header claims a big image. In Debug the assert(0) fired
before the nofail check, so such a file aborted Debug builds instead of
failing the load. Callers without nofail are unchanged (assert, then abort).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard Geldreich
2026-10-23 18:08:46 -04:00
co-authored by Claude Opus 5.5
parent a14c492262
commit 73b648c704
+10 -10
View File
@@ -47,10 +47,10 @@ namespace basisu
// Basic sanity check min_new_capacity
if (!can_fit_into_size_t((uint64_t)min_new_capacity * element_size))
{
assert(0);
if (nofail_flag)
return false;
assert(0);
container_abort("elemental_vector::increase_capacity: requesting too many elements\n");
}
@@ -79,11 +79,11 @@ namespace basisu
if (!can_fit_into_size_t(new_capacity_u64))
{
assert(0);
if (nofail_flag)
return false;
assert(0);
container_abort("elemental_vector::increase_capacity: vector too large\n");
}
}
@@ -92,11 +92,11 @@ namespace basisu
if (!can_fit_into_size_t(desired_size_u64))
{
assert(0);
if (nofail_flag)
return false;
assert(0);
container_abort("elemental_vector::increase_capacity: vector too large\n");
}
@@ -111,11 +111,11 @@ namespace basisu
if (!new_p)
{
fprintf(stderr, "elemental_vector::increase_capacity: Allocation failed!\n");
assert(0);
if (nofail_flag)
return false;
assert(0);
container_abort("elemental_vector::increase_capacity: realloc() failed allocating %zu bytes", desired_size);
}
@@ -136,11 +136,11 @@ namespace basisu
if (!new_p)
{
fprintf(stderr, "elemental_vector::increase_capacity: Allocation failed!\n");
assert(0);
if (nofail_flag)
return false;
assert(0);
container_abort("elemental_vector::increase_capacity: malloc() failed allocating %zu bytes", desired_size);
}