You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Each of the six discarded expressions are invalid. The first five are out of bounds, while the sixth is an impossible reinterpretation. The program compiles normally.
The primary issue with allowing the creation of invalid references at compile time is that they are indistinguishable from valid references at runtime by runtime safety checks.
Compile and run example program with zig run ub_subsequent_runtime_use.zig ub_subsequent_runtime_use.zig:
vardata: [32]u8= .{'a'} **32;
pubfnmain() void {
constptr1: [*]u8=data[0..32];
// Slice of 32 bytes above the actual declaration at runtime.constptr2=ptr1[32..64];
// All subsequent runtime safety checks are based on incorrect information.constless: []constu8=ptr2[0..16];
// The random memory will probably be usable.@import("std").debug.print("{s}\n", .{less[0..16] ++ptr2[16..]});
}
Output:
zig run ub_subsequent_runtime_use.zig
thread {} panic: invalid error
At this point the state of the program is completely undefined and the best outcome is SIGSEGV.
Expected Behaviour
Slicing should not permit the creation of slices which are known to be invalid at compile time.
The text was updated successfully, but these errors were encountered:
Zig Version
0.13.0-dev.46+3648d7df1
Steps to Reproduce and Observed Behaviour
Compile example program with
zig build-obj demo_various_unusable_results.zig
demo_various_unusable_results.zig
:Output:
Each of the six discarded expressions are invalid. The first five are out of bounds, while the sixth is an impossible reinterpretation. The program compiles normally.
The primary issue with allowing the creation of invalid references at compile time is that they are indistinguishable from valid references at runtime by runtime safety checks.
Compile and run example program with
zig run ub_subsequent_runtime_use.zig
ub_subsequent_runtime_use.zig
:Output:
At this point the state of the program is completely undefined and the best outcome is SIGSEGV.
Expected Behaviour
Slicing should not permit the creation of slices which are known to be invalid at compile time.
The text was updated successfully, but these errors were encountered: