-
Notifications
You must be signed in to change notification settings - Fork 819
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
Incorrect generated data_size when using (nanopb_enumopt).int_size #961
Comments
Hmm, are you perhaps generating the protocol definitions into a I think |
Thanks for the prompt reply!
Yes, this is the case - I am generating the protocol definitions into a .pb.c file and compiling the user code as cpp. I think I see what you're saying - the field info is getting generated in a context where |
Yes, |
Hi there,
I’ve been experimenting with using the
(nanopb_enumopt).int_size
option to control the size of the generated enum. However, I’ve been running into issues during encode/decode when I set the enum size to 1 byte. Specifically, it seems like the message descriptor that gets generated for the enum field has an incorrect data_size value that doesn’t respect the int_size option used. But the generated struct does respect the int_size option. This leads to the encode function accessing memory beyond the end of the message structure. I tried to put together a contained example that shows the problem:The generated structures are what I would expect:
However, the generated message descriptor seems to result in an inaccurate data_size for the enum field:
For me this prints “1,4” - the size of the field is 1 byte, but the data_size value is 4 bytes, and data_size is used during encoding to iterate over a void* pointing into the message structure, leading it to access unrelated memory.
Any advice you have to offer would be most appreciated! I'm using nanopb 0.4.8 and clang 15.0.0 targetting arm64-apple-darwin22.6.0.
The text was updated successfully, but these errors were encountered: