aboutsummaryrefslogtreecommitdiff
path: root/std/heap.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-12-22 00:50:30 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-12-22 00:50:30 -0500
commitd917815d8111b98dc237cbe2c723fa63018e02b1 (patch)
treece12771a86b2412ee9692ca73d3ca49abe5da3ce /std/heap.zig
parent8bc523219c66427951e5339550502871547f2138 (diff)
downloadzig-d917815d8111b98dc237cbe2c723fa63018e02b1.tar.gz
zig-d917815d8111b98dc237cbe2c723fa63018e02b1.zip
explicitly return from blocks
instead of last statement being expression value closes #629
Diffstat (limited to 'std/heap.zig')
-rw-r--r--std/heap.zig13
1 files changed, 6 insertions, 7 deletions
diff --git a/std/heap.zig b/std/heap.zig
index d54d921856..605eddb40b 100644
--- a/std/heap.zig
+++ b/std/heap.zig
@@ -17,22 +17,21 @@ pub var c_allocator = Allocator {
};
fn cAlloc(self: &Allocator, n: usize, alignment: u29) -> %[]u8 {
- if (c.malloc(usize(n))) |buf| {
+ return if (c.malloc(usize(n))) |buf|
@ptrCast(&u8, buf)[0..n]
- } else {
- error.OutOfMemory
- }
+ else
+ error.OutOfMemory;
}
fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 {
if (new_size <= old_mem.len) {
- old_mem[0..new_size]
+ return old_mem[0..new_size];
} else {
const old_ptr = @ptrCast(&c_void, old_mem.ptr);
if (c.realloc(old_ptr, usize(new_size))) |buf| {
- @ptrCast(&u8, buf)[0..new_size]
+ return @ptrCast(&u8, buf)[0..new_size];
} else {
- error.OutOfMemory
+ return error.OutOfMemory;
}
}
}