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

Segfault on parse when using "#pragma pack (push, 1)" #4284

Closed
2 tasks done
goversr opened this issue Feb 1, 2024 · 4 comments
Closed
2 tasks done

Segfault on parse when using "#pragma pack (push, 1)" #4284

goversr opened this issue Feb 1, 2024 · 4 comments

Comments

@goversr
Copy link

goversr commented Feb 1, 2024

Description

Hi,

I just wanted to share this with the community. I do not see this as a bug or real issue. More a project related issue, but it took me several hours to find out what was the cause. You can probably directly close the issue. But this way other people with same kind of issue could have an idea what to look for
(i had a hard time to find info on segfault with the lib on the internet; which is a compliment :-))

I had a project that required to a #pragma pack (push, 1) in an include file for one of my structures.
This was incompatible with this json module and resulted in a segfault when calling parse()

Pretty hard to find the issue. I was thinking about os related issues, memory leak in my program, compiler options, ... none of that helped to solve the issue.
Wrote another small program that parsed json and this worked fine. So rules out all of these ideas.

Finally found out by copying some json parsing code in my project's main() function and comment all other code parts and includes. By uncommenting and re-including step by step, I drilled down to this #pragma directive that was the root cause.

Probably it's better not to use too much of this pragma pack (push,1) stuff anyway, or to normalize after the particular structure that needs it... lesson learned :-)

Reproduction steps

add a structure that need special packing and add "#prama pack (push, 1)" in front of it

Expected vs. actual results

no segfault when calling parse()

Minimal code example

Not applicable.

Error messages

segfault 11

Compiler and operating system

g++ / Mint 21.1 - 64bit

Library version

initially happens on 3.10.5

Validation

@goversr goversr changed the title Segfault on parse when using "#prama pack (push, 1)" Segfault on parse when using "#pragma pack (push, 1)" Feb 1, 2024
@gregmarr
Copy link
Contributor

gregmarr commented Feb 1, 2024

Were you using this library in multiple files and only doing the pragma in some of them? That would definitely cause ODR (one definition rule) failures, as you would get different declarations of the same structure in different translation units (files), which is not allowed by the standard, but isn't required to be diagnosed.

@goversr
Copy link
Author

goversr commented Feb 2, 2024

Intresting.

I was using the library in different files, but they all include the same header file with the pragma.

@gregmarr
Copy link
Contributor

gregmarr commented Feb 2, 2024

Did they all include the two headers in the same order? The pragma takes effect from that point forward, so if some files included the json header first, then they wouldn't be affected by it.

@goversr
Copy link
Author

goversr commented Feb 5, 2024

indeed.
as written not a bug report, but rather doc for somebody getting the same segfault.

@goversr goversr closed this as completed Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants