Skip to content

Commit

Permalink
Tidy up the range checking in IndexedColors
Browse files Browse the repository at this point in the history
  • Loading branch information
tealeg committed Sep 13, 2024
1 parent b3ec127 commit 289650d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions xmlStyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1152,12 +1152,18 @@ type xlsxColors struct {
// indexerdColor returns ARGB color string for the given index of the IndexedColors.
// Indexes start from 0, see section 18.8.27 of ECMA-376 (part 1, 4th edition).
func (c *xlsxColors) indexedColor(index int) string {
if c.IndexedColors != nil {
if index < 0 {
return ""
}

if c.IndexedColors != nil && index < len(c.IndexedColors) {
return c.IndexedColors[index].Rgb
} else {
if index < 0 || index > 63 {
return ""
}
}

// This is a weird fallback? Why would we be using indexed colours
// in a file that hasn't defined any?
if index < len(xlsxIndexedColors) {
return xlsxIndexedColors[index]
}
return ""
}

0 comments on commit 289650d

Please sign in to comment.