Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit 289650d

Browse files
committed
Tidy up the range checking in IndexedColors
1 parent b3ec127 commit 289650d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

xmlStyle.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,12 +1152,18 @@ type xlsxColors struct {
11521152
// indexerdColor returns ARGB color string for the given index of the IndexedColors.
11531153
// Indexes start from 0, see section 18.8.27 of ECMA-376 (part 1, 4th edition).
11541154
func (c *xlsxColors) indexedColor(index int) string {
1155-
if c.IndexedColors != nil {
1155+
if index < 0 {
1156+
return ""
1157+
}
1158+
1159+
if c.IndexedColors != nil && index < len(c.IndexedColors) {
11561160
return c.IndexedColors[index].Rgb
1157-
} else {
1158-
if index < 0 || index > 63 {
1159-
return ""
1160-
}
1161+
}
1162+
1163+
// This is a weird fallback? Why would we be using indexed colours
1164+
// in a file that hasn't defined any?
1165+
if index < len(xlsxIndexedColors) {
11611166
return xlsxIndexedColors[index]
11621167
}
1168+
return ""
11631169
}

0 commit comments

Comments
 (0)