From 75c912ca952bf47bbe421030554ef580ff4f3996 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Fri, 4 Nov 2022 21:41:07 -0700 Subject: This closes #1384, fix segmentation fault in `formattedValue` (#1385) - Add nil pointer guard in cell format - Add tests to verify the nil checks in formattedValue Co-authored-by: Zach Clark --- cell.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cell.go') diff --git a/cell.go b/cell.go index eb60441..ebf4681 100644 --- a/cell.go +++ b/cell.go @@ -1292,6 +1292,9 @@ func (f *File) formattedValue(s int, v string, raw bool) string { return v } styleSheet := f.stylesReader() + if styleSheet.CellXfs == nil { + return v + } if s >= len(styleSheet.CellXfs.Xf) { return v } @@ -1306,7 +1309,7 @@ func (f *File) formattedValue(s int, v string, raw bool) string { if ok := builtInNumFmtFunc[numFmtID]; ok != nil { return ok(v, builtInNumFmt[numFmtID], date1904) } - if styleSheet == nil || styleSheet.NumFmts == nil { + if styleSheet.NumFmts == nil { return v } for _, xlsxFmt := range styleSheet.NumFmts.NumFmt { -- cgit v1.2.1