Skip to content

Fix memory overwriting by EnumToString & StringToEnum #4089

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

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

FileEX
Copy link
Contributor

@FileEX FileEX commented Mar 10, 2025

Fixes #4078

Based on PR #4085, it was determined that the strange memory overwriting errors after using EnumToString / StringToEnum are a result of passing a type smaller than 4 bytes, causing the remaining memory to be overwritten (thanks @Merlin for solving this puzzle, although it's simple, I didn't think of it for a moment why the memory was magically overwritten).

The solution is to get rid of casting to a 4-byte size and dynamically determine the type and its size. Tested on several different variants, and I haven't detected any additional issues related to this PR.

I had to modify several enums because now a given value in ADD_ENUM must be associated with the enum provided in IMPLEMENT_ENUM_BEGIN and must be of the same type due to templating. I leave IMPLEMENT_ENUM_CLASS, etc., for compatibility (too many places in the code use it, so I didn't want to change it to IMPLEMENT_ENUM now).

Advanced template methods and complex (hard-to-read) macros are not my strong suit, and I don't claim that this solution is the best possible, but I tried to change as little as possible and maintain compatibility with the current code, and most importantly, as I mentioned – it works, and I haven't noticed any issues.

@Dutchman101
Copy link
Member

Dutchman101 commented Mar 11, 2025

Thanks for the digging and collaboration (@ others), due to release schedule and desired features this was requested and therefore it'll have an expedited merge. After all it was thoroughly researched, too.

It will get further testing in a nightly

@Dutchman101 Dutchman101 merged commit 3ab068b into multitheftauto:master Mar 11, 2025
6 checks passed
MTABot pushed a commit that referenced this pull request Mar 11, 2025
3ab068b Fix memory overwriting by EnumToString & StringToEnum (#4089)
725771e Bump build
469246f Bump build
7b8aa5f Update client en_US pot
@FileEX FileEX deleted the bugfix/enum_reflections branch March 11, 2025 18:28
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

Successfully merging this pull request may close these issues.

Unhandled exception at 0x67ACAF7C after #4076
2 participants