aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-01-09 13:53:56 -0500
committerGitHub <noreply@github.com>2020-01-09 13:53:56 -0500
commit5e345ff0ee9eb70d7f5f7167227f6a1e8903f428 (patch)
tree34d82c8ef040fc30fe895043d7a84d75552d36cf /lib/std
parent5ab5de89c03bf9b3f08dfaa78d3b0fe41a72cdea (diff)
parentc51b79c56e32594e4fb119fc760ae38b69fb9bbb (diff)
downloadzig-5e345ff0ee9eb70d7f5f7167227f6a1e8903f428.tar.gz
zig-5e345ff0ee9eb70d7f5f7167227f6a1e8903f428.zip
Merge pull request #3955 from LemonBoy/fix-1528
Pointer arithmetic affects the alignment factor
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/debug.zig4
-rw-r--r--lib/std/event/fs.zig4
-rw-r--r--lib/std/start.zig4
3 files changed, 7 insertions, 5 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 94f81908da..dfdaca6d3f 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -1084,7 +1084,7 @@ fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo {
std.macho.LC_SYMTAB => break @ptrCast(*std.macho.symtab_command, ptr),
else => {},
}
- ptr += lc.cmdsize; // TODO https://github.com/ziglang/zig/issues/1403
+ ptr = @alignCast(@alignOf(std.macho.load_command), ptr + lc.cmdsize);
} else {
return error.MissingDebugInfo;
};
@@ -2129,7 +2129,7 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u
std.macho.LC_SEGMENT_64 => break @ptrCast(*const std.macho.segment_command_64, @alignCast(@alignOf(std.macho.segment_command_64), ptr)),
else => {},
}
- ptr += lc.cmdsize; // TODO https://github.com/ziglang/zig/issues/1403
+ ptr = @alignCast(@alignOf(std.macho.load_command), ptr + lc.cmdsize);
} else {
return error.MissingDebugInfo;
};
diff --git a/lib/std/event/fs.zig b/lib/std/event/fs.zig
index 5986f07ad3..ce88ac4dc4 100644
--- a/lib/std/event/fs.zig
+++ b/lib/std/event/fs.zig
@@ -1263,7 +1263,7 @@ pub fn Watch(comptime V: type) type {
var ptr = event_buf[0..].ptr;
const end_ptr = ptr + event_buf.len;
var ev: *os.linux.inotify_event = undefined;
- while (@ptrToInt(ptr) < @ptrToInt(end_ptr)) : (ptr += @sizeOf(os.linux.inotify_event) + ev.len) {
+ while (@ptrToInt(ptr) < @ptrToInt(end_ptr)) {
ev = @ptrCast(*os.linux.inotify_event, ptr);
if (ev.mask & os.linux.IN_CLOSE_WRITE == os.linux.IN_CLOSE_WRITE) {
const basename_ptr = ptr + @sizeOf(os.linux.inotify_event);
@@ -1287,6 +1287,8 @@ pub fn Watch(comptime V: type) type {
});
}
}
+
+ ptr = @alignCast(@alignOf(os.linux.inotify_event), ptr + @sizeOf(os.linux.inotify_event) + ev.len);
}
},
os.linux.EINTR => continue,
diff --git a/lib/std/start.zig b/lib/std/start.zig
index b982692a08..c3844e4d1e 100644
--- a/lib/std/start.zig
+++ b/lib/std/start.zig
@@ -142,14 +142,14 @@ fn posixCallMainAndExit() noreturn {
const argc = starting_stack_ptr[0];
const argv = @ptrCast([*][*:0]u8, starting_stack_ptr + 1);
- const envp_optional = @ptrCast([*:null]?[*:0]u8, argv + argc + 1);
+ const envp_optional = @ptrCast([*:null]?[*:0]u8, @alignCast(@alignOf(usize), argv + argc + 1));
var envp_count: usize = 0;
while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
const envp = @ptrCast([*][*:0]u8, envp_optional)[0..envp_count];
if (builtin.os == .linux) {
// Find the beginning of the auxiliary vector
- const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1);
+ const auxv = @ptrCast([*]std.elf.Auxv, @alignCast(@alignOf(usize), envp.ptr + envp_count + 1));
std.os.linux.elf_aux_maybe = auxv;
// Initialize the TLS area
const gnu_stack_phdr = std.os.linux.tls.initTLS() orelse @panic("ELF missing stack size");