Skip to content
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

constructor call on misaligned address #441

Closed
chakaz opened this issue Aug 2, 2023 · 4 comments · Fixed by microsoft/vcpkg#36163
Closed

constructor call on misaligned address #441

chakaz opened this issue Aug 2, 2023 · 4 comments · Fixed by microsoft/vcpkg#36163
Labels

Comments

@chakaz
Copy link

chakaz commented Aug 2, 2023

Hi there!
Our unit test show some runtime errors while using jsoncons with pmr:

/home/shahar/dragonfly/build-dbg/third_party/libs/jsoncons/include/jsoncons/detail/heap_string.hpp:134:36: runtime error: constructor call on misaligned addre
ss 0x55d61bc6204e for type 'struct heap_string_type', which requires 8 byte alignment
0x55d61bc6204e: note: pointer points here
 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00
             ^ 
/home/shahar/dragonfly/build-dbg/third_party/libs/jsoncons/include/jsoncons/detail/heap_string.hpp:64:86: runtime error: member access within misaligned addre
ss 0x55d61bc6204e for type 'struct heap_string', which requires 8 byte alignment
0x55d61bc6204e: note: pointer points here
 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00
             ^ 
/home/shahar/dragonfly/build-dbg/third_party/libs/jsoncons/include/jsoncons/detail/heap_string.hpp:64:86: runtime error: constructor call on misaligned addres
s 0x55d61bc6204e for type 'struct heap_string_base', which requires 8 byte alignment
0x55d61bc6204e: note: pointer points here
 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00
             ^ 

Specifically such prints are printed by this line:
https://github.com/dragonflydb/dragonfly/blob/3b0bd212f46f84e8eda3a02fe99de24f319c9725/src/core/json_test.cc#L127C1-L127C1

The prints are coming from here:
https://github.com/danielaparker/jsoncons/blob/a414677d1333abd110e78c5eec950589956eee54/include/jsoncons/detail/heap_string.hpp#L134C1-L134C1

I think that the issue is actually within jsoncons rather than in our code, and the reason is that the allocation done internally in jsoncons is in byte (byte_alloc.allocate(mem_size);), while later we try to construct a struct in that memory (new(storage)heap_string_type(extra, byte_alloc);), but it's not guaranteed to be aligned (and indeed in my setup it is not)

@chakaz
Copy link
Author

chakaz commented Sep 4, 2023

Hi @danielaparker - just wondering if you also saw this behavior?

@danielaparker
Copy link
Owner

@chakaz - apologies for the late response. This hasn't come up before, possibly because many implementations of allocate, like new, provide maximally aligned storage. But we'll need to address this.

@danielaparker
Copy link
Owner

This should be addressed on master

@chakaz
Copy link
Author

chakaz commented Oct 13, 2023

Thanks @danielaparker!

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

Successfully merging a pull request may close this issue.

2 participants