Add defensive coding fixes to prevent index out of range errors #582
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.
Summary
This PR adds defensive bounds checking in several locations within
cmd/reportwhere array/slice indexing could potentially cause panics. These fixes address reported "index out of range" errors by adding proper validation before accessing array/slice elements.Changes
1. report.go:520 - Reference data lookup
.Values[0]without checking if Values slice has elements2. report.go:386 - Memory benchmark table access
getTableValues()twice, potentially accessing different datamemLatTableValuesvariable for consistency3. dimm.go:628 - 2D array access
dimms[0]has sufficient elements before accessingBankLocatorIdxandLocatorIdx4. report_tables.go:2036 - DIMM table renderer
.Values[0]without bounds checking5. report_tables.go:1222-1224 - String split access
6. system.go:105 - Filesystem fields parsing
fields[len(fields)-2]without length validationlen(fields) >= 2before accessing7. system.go:129 - Mount options parsing
Testing
go build ./cmd/report/...Impact
These defensive coding improvements will prevent panics when processing:
The changes are backward compatible and maintain the existing error handling patterns while making the code more robust.
Review Notes
This PR is marked as draft for initial review. All fixes follow the same defensive coding pattern: check bounds before accessing array/slice elements. No functional behavior changes, only added safety checks.