Skip to content

out of bounds panic does not report the index or bounds #11084

@Jarred-Sumner

Description

@Jarred-Sumner

Zig Version

0.10.0-dev.1120+0ea51f7f4

Steps to Reproduce

  1. Paste this code:
const std = @import("std");
test "oob!" {
    var foo: [123]u8 = undefined;
    foo[std.rand.DefaultPrng.init(100).random().uintAtMost(usize, 99999) + 123] = 123;
}
  1. zig test file.zig

Expected Behavior

Something more like this:

test "oob!" failed
oob.zig:4:5
  2 | test "oob!" {
  3 |    var foo: [123]u8 = undefined; 
  4 |    foo[std.rand.DefaultPrng.init(100).random().uintAtMost(usize, 99999) + 123] = 123;
             ^
panic: index out of bounds
  > index:  1209348
  > bounds: 122

Stack trace:
  test "oob!" | oob.zig:4:5

1 test failure
0 tests passed (0 expectations)
1ms elapsed

Actual Behavior

❯ zig test /Users/jarred/Desktop/oob.zig
Test [1/1] test "ooob"... thread 5048573 panic: index out of bounds
error: the following test command crashed:
/Users/jarred/Desktop/zig-cache/o/c5163ac39be41b38c5688f3aeff793b0/test /Users/jarred/Build/zig/zig

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.error messageThis issue points out an error message that is unhelpful and should be improved.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions