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

Issue found by Svace static analyzer #354

Closed
vvdvortsova opened this issue Jul 16, 2021 · 2 comments
Closed

Issue found by Svace static analyzer #354

vvdvortsova opened this issue Jul 16, 2021 · 2 comments
Assignees
Labels

Comments

@vvdvortsova
Copy link

Hello
This warning found with the Svace.
There is mb can be nil. It can lead to panic.

mb := pb.MediaBox()

due to
return nil

mb is dereferenced here
if cb == nil || mb.equals(*cb) {

@hhrutter hhrutter self-assigned this Jul 16, 2021
@hhrutter hhrutter added the bug label Jul 16, 2021
@hhrutter
Copy link
Collaborator

Hello!
Could you post the whole report, so things stay in context for a better solution.
Thank you for reporting this!

@vvdvortsova
Copy link
Author

vvdvortsova commented Jul 17, 2021

Yes, sure. The whole report looks like this

func appendPageBoxesInfo(...) {
...
mb := pb.MediaBox() // here mb may be nil
cb := pb.CropBox()
if cb == nil || mb.equals(*cb) {// here mb is dereferenced and it may lead to panic
      appendEqualMediaAndCropBoxInfo(ss, pb, unit, currUnit)
      return
}
appendNotEqualMediaAndCropBoxInfo(ss, pb, unit, currUnit)
func (pb PageBoundaries) MediaBox() *Rectangle { // may return nil value 
	if pb.Media == nil {
		return nil
	}
	return pb.Media.Rect
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants