Skip to content

std.hash.RapidHash incorrectly assumes usize is 64 bits #24208

Open
@cryptocode

Description

@cryptocode

Zig Version

0.15.0-dev.822+dd75e7bcb

Steps to Reproduce and Observed Behavior

Test case:

test "RapidHash" {
    const bytes: []const u8 = "abcdefgh" ** 128;
    const hash = std.hash.RapidHash.hash(0, bytes);
    std.debug.print("sizeof usize is {}, hash is {x}\n", .{ @sizeOf(usize), hash });
}

Build on 32-bit target:

zig build -Dtarget=riscv32-linux test

Compilation error:

std/hash/RapidHash.zig:26:25: error: expected type 'usize', found 'u64'
            b = ((r32(k[d..]) << 32) | r32(k[(e - d)..]));
                        ^
std/hash/RapidHash.zig:26:25: note: unsigned 32-bit int cannot represent all possible unsigned 64-bit values

Expected Behavior

The test case should compile and run

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions