refactor(basetype): Refactor functions of Coord3D, Region3D to take reference instead of pointer#2830
refactor(basetype): Refactor functions of Coord3D, Region3D to take reference instead of pointer#2830xezon wants to merge 6 commits into
Conversation
|
| Filename | Overview |
|---|---|
| Core/Libraries/Include/Lib/BaseType.h | Core change: six methods updated from pointer to reference parameters with correct internal dot-notation access. |
| Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp | Derefs getStartPos()/getEndPos() before passing to refactored methods; both return &m_member so can never be null. |
| Core/GameEngine/Source/Common/Audio/AudioEventRTS.cpp | Constructor and copy/assign operators updated; getPosition() results dereferenced inside null-checked branches. |
| Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp | Static crossProduct now called as myDir->crossProduct(*myDir, up, cross); semantically identical to old form, myDir non-null at this point. |
| GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipUpdate.cpp | All six refactored methods updated correctly; gunship->getPosition() returns a member address, safe to deref. |
| GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp | addVelocityTo retains its if (vel != nullptr) guard before dereferencing, preserving the null-safety contract. |
| GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ChinookAIUpdate.h | Inline recordOriginalPosition updated from set(&pos) to set(pos) — correct, pos is already a const reference. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Call site has local Coord3D var"] -->|"old: func(&var)"| B["func(const Coord3D* a)\na->x"]
A -->|"new: func(var)"| C["func(const Coord3D& a)\na.x"]
D["Call site has Coord3D* ptr"] -->|"old: func(ptr)"| B
D -->|"new: func(*ptr)"| C
B -->|null ptr passed| E["UB: nullptr->x inside func"]
C -->|null ptr deref'd| F["UB: *nullptr at call site"]
E -.->|"same crash, earlier in call chain"| F
style C fill:#c8e6c9
style B fill:#ffccbc
style E fill:#ef9a9a
style F fill:#ef9a9a
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["Call site has local Coord3D var"] -->|"old: func(&var)"| B["func(const Coord3D* a)\na->x"]
A -->|"new: func(var)"| C["func(const Coord3D& a)\na.x"]
D["Call site has Coord3D* ptr"] -->|"old: func(ptr)"| B
D -->|"new: func(*ptr)"| C
B -->|null ptr passed| E["UB: nullptr->x inside func"]
C -->|null ptr deref'd| F["UB: *nullptr at call site"]
E -.->|"same crash, earlier in call chain"| F
style C fill:#c8e6c9
style B fill:#ffccbc
style E fill:#ef9a9a
style F fill:#ef9a9a
Reviews (1): Last reviewed commit: "Replicate in Generals" | Re-trigger Greptile
| //We succeeded in calculating the best position. | ||
| location->set( &newPos ); | ||
| location->set( newPos ); | ||
| success = TRUE; |
There was a problem hiding this comment.
nit: indentation, same for FALSE below. Untouched by this though, hopefully it'll get fixed with the formatter PR ;)
There was a problem hiding this comment.
Yes this is outside the scope of this change.
|
LGTM :) |
Caball009
left a comment
There was a problem hiding this comment.
Looks alright to me (I only checked the Zero Hour code).
I checked against 2500+ replays and no mismatches because of this change.
This change refactors functions of Coord3D, Region3D to take reference instead of pointer.
This is more consistent with how standard C++ operator functions look (
operator=(const Coord3D&)). And it clarifies that it expects non-null values.Affected functions are:
Applied by hand.
TODO