Cleanup/assert correctness and formatting#12972
Open
JohnsterID wants to merge 2 commits into
Open
Conversation
Collaborator
|
Note that we may turn off PRECONDITIONs and ASSERTs for stable versions. In that case, those do nothing. I'm against turning them off though. |
Contributor
Author
|
I would be against blanket disabling. ASSERT (always active in debug/release when CVASSERT_ENABLE is defined so we could switch off in release builds) but PRECONDITIONs should never be turned off. |
Remove 98 dead guard clauses after PRECONDITION:
PRECONDITION crashes via BUILTIN_TRAP() on failure, making any guard
clause that checks the same condition unreachable dead code.
- CvMinorCivAI.cpp (69), CvVotingClasses.cpp (6), CvPlot.cpp (5),
CvUnit.cpp (4), CvGlobals.cpp (4), CvCultureClasses.cpp (4),
CvGame.cpp (2), CvTeam.cpp (2), CvCity.cpp (1), CvTechClasses.cpp (1)
Add ASSERT before 58 internal-only bounds-check guard clauses:
Per-instance analysis classified each guard as Lua-exposed (guard-only
correct), internal (ASSERT + guard needed), or business logic (no
macro needed). ASSERT provides debug visibility while the guard clause
preserves safe runtime recovery.
- CvDiplomacyAI.cpp (26), CvMinorCivAI.cpp (25), CvPlayer.cpp (4),
CvVotingClasses.cpp (2), CvTeam.cpp (1)
Fix 3 PRECONDITION misuses where null IS a possible runtime state:
- CvTacticalAI.cpp (2): getBestDefender() can return null between
isEnemyUnit check and lookup (unit killed during AI turn).
PRECONDITION would crash; now ASSERT + guard to continue safely.
- CvReligionClasses.cpp (1): getReligionInfo() can return null for
invalid religion (corrupted save, removed mod). The function already
had a fallback ('No Religion') that was unreachable due to
PRECONDITION crash. Now ASSERT allows the fallback to work.
Place if/else/for/while bodies on separate lines from the condition to allow precise debugger breakpoint placement. 550 formatting fixes across 52 files: - CvGameCoreDLL_Expansion2: 37 files, 374 fixes - FirePlace: 11 files, 158 fixes - CvWorldBuilderMap: 4 files, 18 fixes All changes are whitespace-only — zero functional impact. Compiler generates identical code.
9f56ae5 to
70961f4
Compare
Contributor
Author
|
Conflicts resolved. |
vaderkos
reviewed
Jun 14, 2026
| if ( !_stricmp(szType, "String")) | ||
| return FVARTYPE_STRING; | ||
| if ( !_stricmp(szType, "String")) | ||
| return FVARTYPE_WSTRING; |
Contributor
There was a problem hiding this comment.
What's the difference between those?
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.
Better to place if/else/for/while bodies on separate lines from the condition to allow precise debugger breakpoint placement.