String copy util method and fix Save Manager string copy overflows#3274
Merged
Archez merged 9 commits intoHarbourMasters:developfrom Oct 27, 2023
Merged
String copy util method and fix Save Manager string copy overflows#3274Archez merged 9 commits intoHarbourMasters:developfrom
Archez merged 9 commits intoHarbourMasters:developfrom
Conversation
garrettjoecox
approved these changes
Oct 15, 2023
Contributor
garrettjoecox
left a comment
There was a problem hiding this comment.
Looking for feedback on the two method names:
SohUtils::CopyStringToCharArray
SaveManager::LoadCharArray()
And feedback if we even like LoadCharArray or would rather prefer to drop it in favor of managing the string intermediate values like before (this can be seen by looking at this commit diff)
I think method names and SaveManager change look good, obvious what they are supposed to do and not do 👍
Contributor
|
Conflict here, otherwise ready for merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is attempting to consolidate patterns for copying strings to char arrays safely. The problem was that in the SaveManager we were doing a memcpy and using
string.length()which under-reports the size of the corresponding.c_str()(missing the null terminator). This would lead to situations were if a longer string was copied first, then a shorter string, the null terminator would be missing and so extra characters after the shorter string would be seen from the first longer string.A separate solution for string copying using
strncpyand null terminator handling was done in the spoiler log parsing for hint text, but was repetitive. I have promoted this pattern toSohUtils::CopyStringToCharArrayso that all the different locations in our code can depend on the same solution.Various string copies in the spoiler log parsing, SaveManager context handling, and some gameplay stats are now using this utility method or a helper method from the SaveManager class. In the case of the SaveManager, due to the pattern of
LoadData()needing to assign to a pointer, we still needed string intermediate variables before passing into the copy method, so I created a new helper methodLoadCharArray()then manages the string intermediate var and does the string copy together.Also
FormatJsonHintTextwas called for all the hint text, when really all it does is inject item icons for the child/adult alter hints, so I've removed the unnecessary calls.Not sure if
SohUtilsfeels like the right place for a helper method like, but it fits in my mind as it is technically a utility.Looking for feedback on the two method names:
SohUtils::CopyStringToCharArraySaveManager::LoadCharArray()And feedback if we even like
LoadCharArrayor would rather prefer to drop it in favor of managing the string intermediate values like before (this can be seen by looking at this commit diff)Build Artifacts