Zig: Unexpected error: out of bounds slice

Created on 6 Jan 2020  路  2Comments  路  Source: ziglang/zig

const std = @import("std");
const testing = std.testing;

const ZlibStreamHeader = packed struct {
  cmf: u8,
  flg: u8,
};

const zlibHeader = ZlibStreamHeader{
  .cmf = 0x78,
  .flg = 0x01,
};

test "reproduce 'error: out of bounds slice'" {
  testing.expect(@sizeOf(@TypeOf(zlibHeader)) == 2);

  const ptr1 = @ptrCast([*]const u8, &zlibHeader)[0..@sizeOf(@TypeOf(zlibHeader))];

  //const ptr2 = @ptrCast([*]const u8, &zlibHeader)[0..2]; // same
}

Screen Shot 2020-01-06 at 23 48 18

This is with HEAD (2e53425). Possibly related issues: #1150, #1292

bug stage1

All 2 comments

There's also some related discussion in https://github.com/ziglang/zig/issues/1738#issuecomment-440100426

I'm making a note to add coverage for this test case when doing #3133.

Was this page helpful?
0 / 5 - 0 ratings