Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nil pointer dereference when getting cell formula #290

Closed
lc-jordanfelix opened this issue Nov 8, 2018 · 0 comments
Closed

Nil pointer dereference when getting cell formula #290

lc-jordanfelix opened this issue Nov 8, 2018 · 0 comments

Comments

@lc-jordanfelix
Copy link

Description
When trying to get a cell formula, if the cell has a nil formula, you can get a nil pointer dereference error.

In GetCellFormula() (cell.go line 243+)

for k := range xlsx.SheetData.Row {
	if xlsx.SheetData.Row[k].R == row {
		for i := range xlsx.SheetData.Row[k].C {
			if axis == xlsx.SheetData.Row[k].C[i].R {
				if xlsx.SheetData.Row[k].C[i].F.T == STCellFormulaTypeShared {
					return getSharedForumula(xlsx, xlsx.SheetData.Row[k].C[i].F.Si)
				}
				if xlsx.SheetData.Row[k].C[i].F != nil {
					return xlsx.SheetData.Row[k].C[i].F.Content
				}
			}
		}
	}
}

->

for k := range xlsx.SheetData.Row {
	if xlsx.SheetData.Row[k].R == row {
		for i := range xlsx.SheetData.Row[k].C {
			if axis == xlsx.SheetData.Row[k].C[i].R {
				if xlsx.SheetData.Row[k].C[i].F != nil {
					if xlsx.SheetData.Row[k].C[i].F.T == STCellFormulaTypeShared {
						return getSharedForumula(xlsx, xlsx.SheetData.Row[k].C[i].F.Si)
					}
					return xlsx.SheetData.Row[k].C[i].F.Content
				}
			}
		}
	}
}

Steps to reproduce the issue:

  1. Have a cell with a nil formula
  2. Try running GetCellFormula on above cell

Describe the results you received:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x1175ce8]

Describe the results you expected:
Empty string
Output of go version:

go version go1.11.2 darwin/amd64

Excelize version or commit ID:

github.com/360EntSecGroup-Skylar/excelize v1.4.0

Environment details (OS, Microsoft Excel™ version, physical, etc.):
macOS Mojave (Version 10.14) Terminal

@xuri xuri added the in progress Working in progress label Nov 8, 2018
peiqi111 added a commit to peiqi111/excelize that referenced this issue Nov 8, 2018
xuri added a commit that referenced this issue Nov 8, 2018
@xuri xuri closed this as completed Nov 8, 2018
@xuri xuri removed the in progress Working in progress label Nov 8, 2018
nullfy pushed a commit to nullfy/excelize that referenced this issue Oct 23, 2020
nullfy pushed a commit to nullfy/excelize that referenced this issue Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants