Opened 14 years ago

Closed 14 years ago

#5442 closed defect (fixed)

SWORD2: Code analysis warnings

Reported by: Templier Owned by: eriktorbjorn
Priority: normal Component: Engine: Sword2
Version: Keywords: build
Cc: Game: Broken Sword 2

Description

Here are the warnings I get when compiling the engine using Code Analysis in VS2010. I tried to remove all the obvious false positives. Some warnings look suspicious, others are pointing to correct code that still might benefit from better error checking.

d:\sources\scummvm\scummvm\engines\sword2\music.cpp(500): warning C6308: 'realloc' might return null pointer: assigning null pointer to '_mixBuffer', which is passed as an argument to 'realloc', will cause the original memory block to be leaked d:\sources\scummvm\scummvm\engines\sword2\protocol.cpp(415): warning C6336: Arithmetic operator has precedence over question operator, use parentheses to clarify intent d:\sources\scummvm\scummvm\engines\sword2\protocol.cpp(416): warning C6336: Arithmetic operator has precedence over question operator, use parentheses to clarify intent d:\sources\scummvm\scummvm\engines\sword2\render.cpp(734): warning C6336: Arithmetic operator has precedence over question operator, use parentheses to clarify intent d:\sources\scummvm\scummvm\engines\sword2\render.cpp(735): warning C6336: Arithmetic operator has precedence over question operator, use parentheses to clarify intent d:\sources\scummvm\scummvm\engines\sword2\resman.cpp(305): warning C6011: Dereferencing NULL pointer '_resFiles[cluFileNum].entryTab' d:\sources\scummvm\scummvm\engines\sword2\controls.cpp(188): warning C6011: Dereferencing NULL pointer 'buf'

Note: If you want to try it yourself, you will need: - the create_project patch set, along with the WIP code analysis patch (http://bitbucket.org/Littleboy/scummvm-jt/src) - the following patch to silence some false positives ( http://bitbucket.org/Littleboy/scummvm-jt/src/tip/COMMON%20-%20Add%20annotations%20for%20analysis%20build%20configuration.patch ) - Visual Studio 2010 Ultimate or Team System (create_project support for analysis with VS2005/2008 isn't complete yet)

Ticket imported from: #3087857. Ticket imported from: bugs/5442.

Change History (4)

comment:1 by eriktorbjorn, 14 years ago

I think I have fixed most of these now. I didn't do anything about this one:

d:\sources\scummvm\scummvm\engines\sword2\resman.cpp(305): warning C6011: Dereferencing NULL pointer '_resFiles[cluFileNum].entryTab'

At a quick glance, it looks like a false positive to me. The preceding call to readCluIndex() should have caused _resFiles[cluFileNum].entryTab to be allocaed. True, it doesn't check if malloc() actually succeeded, but I think there are a lot of places where we don't do that.

Could you please check if the others were really fixed by my changes?

comment:2 by Templier, 14 years ago

Yes, all other warnings are now fixed :)

Note that you can easily silence the last one by adding an assert* just before the use of _resFiles[cluFileNum].entryTab.

*in reality it needs a call to the ASSUME macro (that has __analysis_assume(ptr)) instead of a simple assert, but having the assert there doesn't hurt anyway in case the call to readCluIndex() fails.

comment:3 by eriktorbjorn, 14 years ago

Yes, I suppose an assert() or two might be good idea. I've added that, and since you say the others have been fixed I'll consider the bug fixed. Thanks.

comment:4 by eriktorbjorn, 14 years ago

Component: Engine: Sword2
Game: Broken Sword 2
Owner: set to eriktorbjorn
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.