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
This reproduces for me on zig-macos-x86_64-0.8.0-dev.2641+55811d8da but seems quite sensitive to rearranging statements. I looked at the assembly for a while but it's my first time trying to debug something like this. Any help or pointers would be appreciated. Can anyone reproduce this?
const std = @import( "std" );
pub fn main( ) void {
// Problem only happens with Xoroshira128, not other PRNGs
// Problem happens regardless of PRNG seed
var g = std.rand.Xoroshiro128.init( 0 ).random;
// Problem happens with some array sizes but not others
var array = [_]i32 { 0, 0 };
// Prints "0x0, 0x0"
std.debug.print( "before: 0x{x}, 0x{x}\n", .{ array[0], array[1] } );
// Problem happens regardless of what PRNG call we make here
var x = g.int( i32 );
// Prints garbage
std.debug.print( " after: 0x{x}, 0x{x}\n", .{ array[0], array[1] } );
}
The text was updated successfully, but these errors were encountered:
This line "truncates" the random interface, creating a copy of the vtable but not the extra data needed for the implementation. When you call g.int() it tries to get the extended data relative to g, which accesses stack memory that in this case happens to overlap with array.
The recommended way to write this to avoid truncation is
This reproduces for me on zig-macos-x86_64-0.8.0-dev.2641+55811d8da but seems quite sensitive to rearranging statements. I looked at the assembly for a while but it's my first time trying to debug something like this. Any help or pointers would be appreciated. Can anyone reproduce this?
The text was updated successfully, but these errors were encountered: