-
Notifications
You must be signed in to change notification settings - Fork 227
Fix issues reported by zoeontheloose + Undefined Behaviour in ControlSwitches #3541
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
base: master
Are you sure you want to change the base?
Changes from all commits
c45c0f3
e5c72be
e4e947c
fea9ed5
053edab
1bd0dd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -834,6 +834,53 @@ std::string_view ManiacPatch::GetLcfDescription(int data_type, int id, bool is_d | |
| return {}; | ||
| } | ||
|
|
||
| bool ManiacPatch::DecodeStringToInt(std::string_view str, uint32_t& out) { | ||
| /* | ||
| Is a custom 5 bit encoding: | ||
|
|
||
| For the rightmost character c the value is: | ||
| c - A + 1 | ||
|
|
||
| For all other characters c with index i the value is: | ||
| (c - a + 1) << (i * 5) | ||
|
|
||
| Due to integer overflow the max string length is 6. | ||
| */ | ||
|
|
||
| out = 0; | ||
|
|
||
| if (!(str.size() > 0 && str.size() <= 6)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return false; | ||
| } | ||
|
|
||
| auto in_range = [](int32_t value) { | ||
| return value >= 0 && value < 32; | ||
| }; | ||
|
|
||
| int32_t result = (str.back() - 'A' + 1); | ||
|
|
||
| if (!in_range(result)) { | ||
| return false; | ||
| } | ||
|
|
||
| out = static_cast<uint32_t>(result); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The casting here is a bit ugly, |
||
|
|
||
| str.remove_suffix(1); | ||
|
|
||
| for (size_t i = 0; i < str.size(); ++i) { | ||
| result = (str[i] - 'a' + 1); | ||
|
|
||
| if (!in_range(result)) { | ||
| return false; | ||
| } | ||
|
|
||
| int chidx = str.size() - i; | ||
| out += static_cast<uint32_t>(result << (chidx * 5)); | ||
| } | ||
|
|
||
| return out; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if |
||
| } | ||
|
|
||
| bool ManiacPatch::GlobalSave::Load() { | ||
| if (!Player::IsPatchManiac()) { | ||
| return true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe any log entry/assert for
val>2?