Add test for issue #3435

This commit is contained in:
Feoramund
2025-06-19 19:54:12 -04:00
parent c2f3d074e3
commit 7022ad8378
3 changed files with 40 additions and 0 deletions
+1
View File
@@ -17,6 +17,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style
..\..\..\odin test ..\test_issue_2637.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2666.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2694.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_3435.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_4210.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_4364.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_4584.odin %COMMON% || exit /b
+1
View File
@@ -18,6 +18,7 @@ $ODIN test ../test_issue_2615.odin $COMMON
$ODIN test ../test_issue_2637.odin $COMMON
$ODIN test ../test_issue_2666.odin $COMMON
$ODIN test ../test_issue_2694.odin $COMMON
$ODIN test ../test_issue_3435.odin $COMMON
$ODIN test ../test_issue_4210.odin $COMMON
$ODIN test ../test_issue_4364.odin $COMMON
$ODIN test ../test_issue_4584.odin $COMMON
+38
View File
@@ -0,0 +1,38 @@
package main
import "base:runtime"
import "core:mem"
import "core:testing"
import "core:time"
@test
test_issue_3435 :: proc(t: ^testing.T) {
testing.set_fail_timeout(t, time.Second)
allocator: mem.Buddy_Allocator
data := runtime.make_aligned([]byte, 64, 32)
defer delete(data)
// mem.buddy_allocator_init(&allocator, data, 32)
// Bypass the assertion that would normally keep this from happening by
// manually putting the allocator together.
allocator.head = cast(^mem.Buddy_Block)raw_data(data)
allocator.head.size = len(data)
allocator.head.is_free = true
allocator.tail = mem.buddy_block_next(allocator.head)
allocator.alignment = 32
context.allocator = mem.buddy_allocator(&allocator)
// Three allocations in the space above is all that's needed to reproduce
// the bug seen in #3435; this is the most minimal reproduction possible.
a := make([]u8, 1)
testing.expect(t, len(a) == 1)
b := make([]u8, 1)
testing.expect(t, len(b) == 0)
c := make([]u8, 1)
testing.expect(t, len(c) == 0)
// With the bugfix in place, the allocator should be sensible enough to not
// fall into an infinite loop anymore, even if the assertion is disabled.
}