🔍 Module Scanned
(automated audit scan)
📝 Summary
The function uses for coordinate wrapping, while the closely related function uses . This inconsistency suggests a potential bug where may produce incorrect (potentially out-of-bounds) local coordinates when given negative world coordinates, causing crashes or data corruption when accessing blocks at negative positions.
📍 Location
🔴 Severity: High
- High: Memory corruption, crashes when accessing blocks at negative world coordinates (e.g., terrain near spawn, exploration in negative direction)
💥 Impact
When a player moves to negative X or Z coordinates (e.g., exploring west or north of spawn), block access through and will receive incorrect local coordinates. If returns a negative value that is then cast to , this causes an out-of-bounds access or crash. Minecraft-style voxel games commonly have players exploring negative coordinate space, making this a high-impact user-visible bug.
🔎 Evidence
The inconsistency between (which correctly handles negative division) and (which may not produce correct positive remainders for negative inputs) is the core issue.
Callers in and use this function to get local block coordinates from world positions. If :
- returns (correct)
- should return but may produce garbage due to behavior
🛠️ Proposed Fix
Use a consistent approach that guarantees positive remainders for negative inputs:
Or use the standard math pattern for guaranteed-positive modulo:
✅ Acceptance Criteria
📚 References
- Zig 0.16 documentation: computes remainder with result sign matching divisor for positive divisors
- Zig 0.16 : integer division rounding toward negative infinity (correct for negative coordinates)
- Minecraft coordinate system: world extends infinitely in all directions from origin (0, 0)
- Related: at line 252 correctly uses for negative-aware division
🔍 Module Scanned
(automated audit scan)
📝 Summary
The function uses for coordinate wrapping, while the closely related function uses . This inconsistency suggests a potential bug where may produce incorrect (potentially out-of-bounds) local coordinates when given negative world coordinates, causing crashes or data corruption when accessing blocks at negative positions.
📍 Location
🔴 Severity: High
💥 Impact
When a player moves to negative X or Z coordinates (e.g., exploring west or north of spawn), block access through and will receive incorrect local coordinates. If returns a negative value that is then cast to , this causes an out-of-bounds access or crash. Minecraft-style voxel games commonly have players exploring negative coordinate space, making this a high-impact user-visible bug.
🔎 Evidence
The inconsistency between (which correctly handles negative division) and (which may not produce correct positive remainders for negative inputs) is the core issue.
Callers in and use this function to get local block coordinates from world positions. If :
🛠️ Proposed Fix
Use a consistent approach that guarantees positive remainders for negative inputs:
Or use the standard math pattern for guaranteed-positive modulo:
✅ Acceptance Criteria
📚 References