Feoramund 2 місяців тому
батько
коміт
7022ad8378
3 змінених файлів з 40 додано та 0 видалено
  1. 1 0
      tests/issues/run.bat
  2. 1 0
      tests/issues/run.sh
  3. 38 0
      tests/issues/test_issue_3435.odin

+ 1 - 0
tests/issues/run.bat

@@ -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 - 0
tests/issues/run.sh

@@ -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 - 0
tests/issues/test_issue_3435.odin

@@ -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.
+}