aboutsummaryrefslogtreecommitdiff
path: root/std/cstr.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-06-04 01:09:15 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-06-04 01:39:57 -0400
commit96164ce61377b36bcaf0c4087ca9b1ab822b9457 (patch)
treedb4ab07dd179c8f72a05028edb6ad60bfabd4a74 /std/cstr.zig
parent4c273126dfc44cf4fcf9d5d97bf1cb1da07d7bd7 (diff)
downloadzig-96164ce61377b36bcaf0c4087ca9b1ab822b9457.tar.gz
zig-96164ce61377b36bcaf0c4087ca9b1ab822b9457.zip
disallow single-item pointer indexing
add pointer arithmetic for unknown length pointer
Diffstat (limited to 'std/cstr.zig')
-rw-r--r--std/cstr.zig10
1 files changed, 5 insertions, 5 deletions
diff --git a/std/cstr.zig b/std/cstr.zig
index d60adf8faa..d9106769c1 100644
--- a/std/cstr.zig
+++ b/std/cstr.zig
@@ -57,7 +57,7 @@ pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![]u8 {
pub const NullTerminated2DArray = struct {
allocator: *mem.Allocator,
byte_count: usize,
- ptr: ?*?*u8,
+ ptr: ?[*]?[*]u8,
/// Takes N lists of strings, concatenates the lists together, and adds a null terminator
/// Caller must deinit result
@@ -79,12 +79,12 @@ pub const NullTerminated2DArray = struct {
errdefer allocator.free(buf);
var write_index = index_size;
- const index_buf = ([]?*u8)(buf);
+ const index_buf = ([]?[*]u8)(buf);
var i: usize = 0;
for (slices) |slice| {
for (slice) |inner| {
- index_buf[i] = &buf[write_index];
+ index_buf[i] = buf.ptr + write_index;
i += 1;
mem.copy(u8, buf[write_index..], inner);
write_index += inner.len;
@@ -97,12 +97,12 @@ pub const NullTerminated2DArray = struct {
return NullTerminated2DArray{
.allocator = allocator,
.byte_count = byte_count,
- .ptr = @ptrCast(?*?*u8, buf.ptr),
+ .ptr = @ptrCast(?[*]?[*]u8, buf.ptr),
};
}
pub fn deinit(self: *NullTerminated2DArray) void {
- const buf = @ptrCast(*u8, self.ptr);
+ const buf = @ptrCast([*]u8, self.ptr);
self.allocator.free(buf[0..self.byte_count]);
}
};