oakmound / oak

A pure Go game engine
Apache License 2.0
1.55k stars 83 forks source link

Issue found by Svace static analyzer #160

Closed vvdvortsova closed 3 years ago

vvdvortsova commented 3 years ago

Hello This warning found with the Svace. [dereference] '0' is passed to function 'entities.NewMoving' as 7th parameter at core.go:73 https://github.com/oakmound/oak/blob/49338760bf9aa81e21e30dbe8ece44fc43e61fa5/examples/pong/main.go#L74 https://github.com/oakmound/oak/blob/49338760bf9aa81e21e30dbe8ece44fc43e61fa5/entities/moving.go#L17 cid is dereferenced here. at moving.go:19 https://github.com/oakmound/oak/blob/49338760bf9aa81e21e30dbe8ece44fc43e61fa5/entities/moving.go#L19 It may lead to panic.

vvdvortsova commented 3 years ago

The same https://github.com/oakmound/oak/blob/49338760bf9aa81e21e30dbe8ece44fc43e61fa5/examples/pong/main.go#L42

200sc commented 3 years ago
func (cid CID) Parse(e Entity) CID {
    if cid == 0 {
        return e.Init()
    }
    return cid
}

Reopen with an actual panic if found.

200sc commented 3 years ago

To clarify: cid is not dereferenced, as the method has a value receiver, not a pointer receiver. The method also expects to receive a 0 and its whole job is built around accepting that 0.

vvdvortsova commented 3 years ago

You are right. I agree with you. Sorry. It's FP. On your case we'll fix it.