blob: 3830869edb7015851e20dddf566a1fb497b8b9ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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.
}
|