Skip to content

chore: Add static asserts to verify the size of arrays - #3389

Open
xezon wants to merge 3 commits into
TheSuperHackers:mainfrom
xezon:xezon/chore-array-size-static-asserts
Open

xezon wants to merge 3 commits into
TheSuperHackers:mainfrom
xezon:xezon/chore-array-size-static-asserts

Conversation

@xezon

@xezon xezon commented Sep 29, 2026

Copy link
Copy Markdown

Merge with Rebase

This change fixes 2 arrays in wdump and adds static asserts for various C arrays that correspond to enum values or bit flags. This makes the code more resilient to mistakes from editing an enumeration without updating the related arrays.

AI Use

This change was 99% generated.

TODO

  • Add pull id to commit titles
  • Replicate in Generals

xezon and others added 3 commits September 29, 2026 21:26
…hader functions

The name tables for the primary gradient and the detail color function
were shorter than their W3DSHADER_*_MAX enumerations, so dumping a
shader that uses bump environment luminance, modulate 2x, add signed,
add signed 2x, scale 2x or mod alpha add color read past the end of
the table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds static_assert's for enum indexed name, lookup and function tables,
so that editing an enum fails to compile until the associated array is
updated.

Arrays that were declared with an explicit enum count now use an unsized
bound, because an explicit bound silently zero fills missing entries.
Enums without a count get one. The waveTypeInfo table gets an explicit
zero entry for WaveTypeStationary, which it previously got through zero
fill, and the <undefined> padding of the memory category names is
replaced by the assert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Fix Is fixing something, but is not user facing labels Sep 29, 2026
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f7692d28-b94f-4fd2-aafe-b3092e20f824

📥 Commits

Reviewing files that changed from the base of the PR and between 10f5504 and be8105b.

📒 Files selected for processing (63)
  • Core/GameEngine/Include/Common/AudioEventInfo.h
  • Core/GameEngine/Include/Common/Debug.h
  • Core/GameEngine/Include/Common/Dict.h
  • Core/GameEngine/Include/GameClient/ControlBar.h
  • Core/GameEngine/Include/GameClient/Gadget.h
  • Core/GameEngine/Include/GameClient/GameWindow.h
  • Core/GameEngine/Include/GameClient/GlobalLanguage.h
  • Core/GameEngine/Include/GameClient/Image.h
  • Core/GameEngine/Include/GameClient/MetaEvent.h
  • Core/GameEngine/Include/GameNetwork/GameSpy/PeerDefs.h
  • Core/GameEngine/Source/Common/INI/INIAudioEventInfo.cpp
  • Core/GameEngine/Source/Common/System/Debug.cpp
  • Core/GameEngine/Source/Common/System/Radar.cpp
  • Core/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp
  • Core/GameEngine/Source/GameClient/GlobalLanguage.cpp
  • Core/GameEngine/Source/GameClient/Input/Mouse.cpp
  • Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp
  • Core/GameEngine/Source/GameNetwork/GameSpy/Chat.cpp
  • Core/GameEngine/Source/GameNetwork/GameSpyOverlay.cpp
  • Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DDebrisDraw.cpp
  • Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
  • Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp
  • Core/Libraries/Source/Compression/CompressionManager.cpp
  • Core/Libraries/Source/WWVegas/WW3D2/assetstatus.cpp
  • Core/Libraries/Source/WWVegas/WW3D2/dx8caps.cpp
  • Core/Libraries/Source/WWVegas/WW3D2/dx8caps.h
  • Core/Libraries/Source/WWVegas/WW3D2/formconv.cpp
  • Core/Libraries/Source/WWVegas/WW3D2/texturefilter.cpp
  • Core/Libraries/Source/WWVegas/WW3D2/texturefilter.h
  • Core/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp
  • Core/Tools/W3DView/Vector3RndCombo.cpp
  • GeneralsMD/Code/GameEngine/Include/GameClient/Shadow.h
  • GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
  • GeneralsMD/Code/GameEngine/Include/GameLogic/LocomotorSet.h
  • GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
  • GeneralsMD/Code/GameEngine/Include/GameLogic/Module/StealthUpdate.h
  • GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h
  • GeneralsMD/Code/GameEngine/Include/GameLogic/ObjectIter.h
  • GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
  • GeneralsMD/Code/GameEngine/Include/GameLogic/Weapon.h
  • GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h
  • GeneralsMD/Code/GameEngine/Source/Common/RTS/Handicap.cpp
  • GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
  • GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SimpleObjectIterator.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureCollapseUpdate.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/WeaponSet.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/Scripts.cpp
  • GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DBufferManager.cpp
  • GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/part_ldr.cpp
  • GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/shader.cpp
  • GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/w3d_file.h
  • GeneralsMD/Code/Tools/GUIEdit/Source/Properties.cpp
  • GeneralsMD/Code/Tools/WorldBuilder/src/DrawObject.cpp
  • GeneralsMD/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp
  • GeneralsMD/Code/Tools/wdump/chunk_d.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


Walkthrough

The changes add enum end or count values and compile-time array-size checks across the core engine, GeneralsMD engine, graphics libraries, and tools. Several initialized arrays now infer their sizes, and some existing labels and assertion messages change.

Changes

Enum and table consistency

Layer / File(s) Summary
Core enum boundaries and name-table checks
Core/GameEngine/Include/Common/*, Core/GameEngine/Include/GameClient/*, Core/GameEngine/Source/Common/INI/INIAudioEventInfo.cpp, Core/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp, Core/GameEngine/Source/GameClient/GlobalLanguage.cpp
Core enums gain end or count values. Compile-time checks compare audio, command, window, image, category, and language name tables with their enum boundaries.
Core runtime and network tables
Core/GameEngine/Include/Common/Debug.h, Core/GameEngine/Include/GameNetwork/GameSpy/PeerDefs.h, Core/GameEngine/Source/Common/System/*, Core/GameEngine/Source/GameClient/Input/Mouse.cpp, Core/GameEngine/Source/GameNetwork/*
Debug, radar, cursor, transfer-rule, and GameSpy arrays use inferred sizes or gain compile-time size checks.
Core graphics and library tables
Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/*, Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp, Core/Libraries/Source/Compression/CompressionManager.cpp, Core/Libraries/Source/WWVegas/WW3D2/*, Core/Libraries/Source/WWVegas/WWDebug/wwmemlog.cpp, Core/Tools/W3DView/Vector3RndCombo.cpp
Graphics and library tables infer their sizes or gain compile-time checks. Device-type enums gain count values. Four padding entries are removed from the memory-category table.
GeneralsMD enum boundaries and checks
GeneralsMD/Code/GameEngine/Include/GameClient/Shadow.h, GeneralsMD/Code/GameEngine/Include/GameLogic/*, GeneralsMD/Code/GameEngine/Include/GameLogic/Module/*, GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp, GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp, GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SimpleObjectIterator.cpp, GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp
Gameplay enums gain end or count values. Related name tables and procedure arrays gain compile-time checks against those boundaries.
GeneralsMD gameplay array checks
GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponSet.h, GeneralsMD/Code/GameEngine/Source/Common/RTS/Handicap.cpp, GeneralsMD/Code/GameEngine/Source/GameClient/{Drawable.cpp,InGameUI.cpp}, GeneralsMD/Code/GameEngine/Source/GameLogic/Object/{Locomotor.cpp,Object.cpp,WeaponSet.cpp}, GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/*, GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/Scripts.cpp
Gameplay and UI arrays infer their sizes or gain compile-time checks against declared counts. Several assertion messages change.
GeneralsMD graphics and tool tables
GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DBufferManager.cpp, GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/*, GeneralsMD/Code/Tools/GUIEdit/Source/Properties.cpp, GeneralsMD/Code/Tools/WorldBuilder/src/*, GeneralsMD/Code/Tools/wdump/chunk_d.cpp
Graphics and tool tables gain inferred sizes or compile-time checks. The W3D dump label tables add shader labels and checks against enum limits.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: bobtista

Merge Risk: ⚪ Minimal · up to be810

The enum/table checks preserve the inspected mappings, and no concrete user-facing regression is established. The change is ready to merge with normal build checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to be810

The shared declarations and compile-time checks do not show a new security exposure or changed runtime flow in the inspected consumers. Review of all dependent consumers and builds remains incomplete.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated effect on the inspected network-adjacent path is a compile-time table-count guard, not expanded reachability from lobby data. This conclusion does not cover every dependent consumer.

Trust Boundaries and Controls

  • observed — The inspected lobby path obtains game information but selects display colors with fixed GSCOLOR_GAME, GSCOLOR_GAME_FULL, or GSCOLOR_GAME_CRCMISMATCH indices.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: adding compile-time array-size assertions.
Description check ✅ Passed The description accurately describes the static assertions, enum-related arrays, follow-up context, and intended resilience against mismatched array sizes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Low risk] Adds compile-time array size verification checks.

The PR appears safe to merge; no actionable regression was identified.

Summary

The PR adds compile-time checks that array lengths match enum counts or flag-name lists. It also fills two wdump shader-label arrays and makes the stationary wave-table entry explicit.

Reviews (1) · Last reviewed commit: "chore: Add static asserts to verify the ..."

ST_ENEMIES = 0x0080,
ST_EVERYONE = 0x0100,

SOUND_TYPE_END // keep after the last named flag

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming SOUND_TYPE_END is now 0x101, I don't know what that value signifies.

There are many _END additions to binary enums in this pr.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It marks the end of the flags

@Caball009 Caball009 Sep 29, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that's useful for regular enums, but not ones with binary values.

SOUND_TYPE_END == (ST_UI | ST_EVERYONE), so what's 'end' useful for here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in static_assert:

static_assert(1 << (ARRAY_SIZE(theSoundTypeNames) - 2) == SOUND_TYPE_END - 1, "Incorrect array size");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that looks a bit clunky to me, but it works.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes looks quite a bit unholy. I can wrap it into a helper function to simplify the call sites.

COMMANDUSABLE_GAME = (1 << 1), // Command is usable when not in Shell
COMMANDUSABLE_OBSERVER = (1 << 2), // TheSuperHackers @feature Command is usable when observing

COMMAND_USABLE_IN_TYPE_END, // keep after the last named flag

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe name consistency needs looking at.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Minor Severity: Minor < Major < Critical < Blocker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants