Skip to content

[[Crashed]] 0xC0000005 at bm::bit_out<bm::encoder>::put_bits #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
WCC1998 opened this issue Apr 16, 2025 · 4 comments
Open

[[Crashed]] 0xC0000005 at bm::bit_out<bm::encoder>::put_bits #80

WCC1998 opened this issue Apr 16, 2025 · 4 comments

Comments

@WCC1998
Copy link

WCC1998 commented Apr 16, 2025

#include "Services/ScreenCompatibility/BitMagic/src/bm.h"
#include "Services/ScreenCompatibility/BitMagic/src/bmserial.h"
#include "Services/ScreenCompatibility/BitMagic/src/bmundef.h"
......
void test_bm()
{
    bm::bvector<> f3;
    f3.clear();
    f3.set(65535);
    f3.set(65526);
    f3.set(65486);
    f3.set(65447);
    f3.set(65504);
    f3.set(32639);
    f3.set(18873);
    f3.set(87);
    f3.set(145);
    f3.set(48);
    f3.set(105);
    f3.set(8);
    f3.set(66);
    f3.set(25);

    bm::serializer<bm::bvector<>> ser;
    ser.byte_order_serialization(false);
    ser.gap_length_serialization(false);
    bm::serializer<bm::bvector<>>::buffer buf;
    ser.serialize(f3, buf);
}
......
int main(int argc, char *argv[])
{
    test_bm();
......

Up here is my test code, it crashed at bm::bit_out<bm::encoder>::put_bits(unsigned value, unsigned count) like below:

Image

It's weird that it only crash when I use this lib in my project. Once I write a simple test, I mean a simple C++ program contains only the two test_bm and main functions, it runs perfectly. And one more weird thing is that when the code crash, process stack seems not valid like below:

Image

My compiler is 'VS Community 2022 Release msvc_x86' with Qt5.15, hope someone can help me, thank you.

@WCC1998
Copy link
Author

WCC1998 commented Apr 16, 2025

Seems like it's the function below runs incorrect:

BMFORCEINLINE
unsigned int bsr_asm32(unsigned int value) BMNOEXCEPT
{   
  __asm  bsr  eax, value
}

Image

It give a wrong result of logv

Image

@WCC1998
Copy link
Author

WCC1998 commented Apr 16, 2025

After modify those function, it finally runs correct:

BMFORCEINLINE
unsigned int bsr_asm32(unsigned int value) BMNOEXCEPT
{   
//   __asm  bsr  eax, value
return 31u - std::countl_zero(value);
}

BMFORCEINLINE
unsigned int bsf_asm32(unsigned int value) BMNOEXCEPT
{   
//   __asm  bsf  eax, value
return std::countr_zero(value);
}

I don't know why same compiler and same code can runs different, hope somebody can find out.

@tlk00
Copy link
Owner

tlk00 commented May 1, 2025

What is the compiler (ok, i see that it is VS 22) and the platform and the compile options here?
These BSR asms are pretty old... always worked.
Some compilers sometimes have bugs on -O3 level (just a guess).

@tlk00
Copy link
Owner

tlk00 commented May 2, 2025

We are looking at this issue and suspect a compilation bug...
Can you please post a disassembly printout at the place of failure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants