Repository navigation
fix(wwlib): Load the StringClass hash word with memcpy instead of an unsigned int cast - #3630
CryoTheRenegade wants to merge 2 commits into
Conversation
HashTemplateKeyClass<StringClass>::Get_Hash_Value read four characters of the string as an unsigned int through a pointer cast. Copy them into an unsigned int with memcpy instead. The offset, length check and byte order are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
String hash input read Core/Libraries/Source/WWVegas/WWLib/hashtemplate.h |
The specialization copies four bytes into a uint32_t with memcpy. The hash calculation remains unchanged. |
Priority:
Estimated code review effort: 1 (Trivial) | ~5 minutes
Change: Refactor
Possibly related PRs
- TheSuperHackers/GeneralsGameCode#3532: Replaces pointer-based bit reinterpretation in several locations, including another hash specialization in
hashtemplate.h. - TheSuperHackers/GeneralsGameCode#3580: Replaces unsafe type reinterpretation in vector and color code.
Suggested reviewers: xezon
Merge Risk: 
Minimal · up to 3490a
-
The change removes unsafe memory access while preserving hash behavior, with no merge-blocking risk identified.
Pre-merge checks: 
4
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
[Low impact] The PR appears safe to merge; no actionable issues were found.
|
Skyaero42
left a comment
There was a problem hiding this comment.
I think this is a fix rather than a refactor.
| } | ||
| unsigned int hval = *((const unsigned int*)(buffer+len-8)); | ||
| unsigned int hval; | ||
| memcpy(&hval, buffer+len-8, sizeof(hval)); |
There was a problem hiding this comment.
I believe you should not assume that an unsigned int always have 4 bytes. Instead uint32_t should be used instead, which guarantees four bytes.
The hash word is four bytes copied from the string, so declare it as uint32_t rather than relying on unsigned int being four bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow-up to #3580, #3605, #3617 and #3628.
HashTemplateKeyClass<StringClass>::Get_Hash_Valuereads four characters of the string through anunsigned intpointer. Reading acharbuffer as anunsigned intis undefined behavior, the same problem as #3521, and the address isn't necessarily 4-byte aligned.The function now copies the four bytes into a
uint32_twithmemcpy, so the size of the load no longer depends on the size ofunsigned int. The offset, the length check and the byte order are unchanged, so every string gets the same hash as before.hashtemplate.hnow includes<string.h>formemcpydirectly. Its existing includes only bring it in through the VC6 branch ofbit_adapter.h.uint32_talready comes in throughstdint_adapter.hin the precompiled header.This hash is used for the texture, hierarchy tree and definition lookup tables.
Evidence
main.__TIME__string inWinMain.uint32_tinstead ofunsigned int: the disassembly ofassetmgr.cpp.obj, which uses this hash, is identical before and after on VS 2026 Release and VC6 Release.AI Disclosure
Claude Opus 5.5 was used to aid in implementation and to compare the disassembly.