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

No Magic Numbers for Preset Location Exclusions #3801

Conversation

Malkierian
Copy link
Contributor

@Malkierian Malkierian commented Jan 4, 2024

Previously, a change to the RandomizerCheck enum caused all location exclusions in the presets to be off by 1 because they were feeding literal strings. This adds FormatLocations and PRESET_ENTRY_TYPE_CPP_STRING to allow for feeding RandomizerCheck values directly in presets instead of a string with magic numbers to prevent this in the future.

Build Artifacts

…r feeding `RandomizerCheck` values directly in presets instead of a string with magic numbers.
@@ -866,7 +872,8 @@ const std::vector<PresetEntry> spockRacePresetEntries = {
PRESET_ENTRY_S32("gRandomizeDampeHint", 1),
PRESET_ENTRY_S32("gRandomizeDoorOfTime", RO_DOOROFTIME_OPEN),
PRESET_ENTRY_S32("gRandomizeEnableBombchuDrops", 1),
PRESET_ENTRY_STRING("gRandomizeExcludedLocations", "78,143,144,229,"),
PRESET_ENTRY_CPP_STRING("gRandomizeExcludedLocations", FormatLocations(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use FormatLocations inside applyPreset? Having a type like ENUM_LIST_TO_STRING where the value is a vector of ints, and then you can just string build in applyPreset directly, rather than in the header.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing it here means the std::string is stored here in the preset entries vector, so the .c_str() call will return a pointer that will stay valid. If we call format string in applyPreset, the pointer returned from the .c_str() in that function will point to a local std::string that gets freed at the end of the function, potentially resulting in a use after free. Unless the string gets copied as part of CVarSetString perhaps? Which means it would then be fine to do that.

soh/soh/Enhancements/presets.cpp Outdated Show resolved Hide resolved
@garrettjoecox garrettjoecox merged commit 61cf2bd into HarbourMasters:develop-macready Feb 2, 2024
8 checks passed
@Malkierian Malkierian deleted the preset-location-exclusions branch February 3, 2024 04:32
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.

None yet

5 participants