ImHex icon indicating copy to clipboard operation
ImHex copied to clipboard

[Bug] std::mem::read_unsigned won't accept any endian but native

Open summivox opened this issue 2 years ago • 2 comments

Operating System

Windows

What's the issue you encountered?

std::mem::read_unsigned takes an endianness parameter, but anything but the default (native endianness) returns this error:

error[E0012]: Built-in function error.
Invalid endian value.
hint: Try one of the values in the std::core::Endian enum.

The Endian enum seems to be only defined in std::mem. Regardless of I use the enum or directly use the integer , the same error applies. Only when I use 0 or std::mem:Endian::Native does it not throw.

How can the issue be reproduced?

In pattern editor:

#include <std/mem.pat>
fn Test(auto base) {
    u32 x = std::mem::read_unsigned(base, 4, std::mem::Endian::Big);
}

ImHex Version

1.24.3

ImHex Build Type

  • [X] Nightly or built from sources

Installation type

MSI

Additional context?

I'm not sure where to find the nightly commit hash; downloaded via https://imhex.werwolv.net/ .

summivox avatar Nov 07 '22 08:11 summivox

Hey When you updated to the nightly build, did you also update the pattern language standard library in the Content Store? I just ran your script locally and it works fine here.

WerWolv avatar Nov 08 '22 17:11 WerWolv

I used the nightly MSI installer. For now I am manually byte-swapping... will try again when the #include fix is included in the next release.

summivox avatar Nov 09 '22 02:11 summivox

I can confirm this happens on Linux too. Even with the #pragma directive

Rufis01 avatar Feb 25 '23 21:02 Rufis01

I can reproduce it only if the default endianness is set to Big (happens if set with a pragma directive or with std::core::set_endian). Cannot reproduce if it is set to Native or Little.

#include <std/io.pat>
#include <std/mem.pat>

#pragma endian big

std::print("{}", std::mem::read_unsigned($, 1, std::mem::Endian::Big));

the-blank-x avatar Mar 20 '23 14:03 the-blank-x

Hey, I fixed a bug for a related issue a few days ago. Could you try downloading the latest nightly from https://imhex.werwolv.net and check if it still happens for you? I can't reproduce it myself anymore

WerWolv avatar Mar 20 '23 15:03 WerWolv

It works correctly now, thank you!

the-blank-x avatar Mar 20 '23 15:03 the-blank-x

Awesome thanks!

WerWolv avatar Mar 20 '23 15:03 WerWolv