cppcheck - Sourcecode analysis

cppcheck - Sourcecode analysis

Postby StefanP.MUC » 26 Mar 2011, 10:55

Just found a tool that could help making the code of OD better: cppcheck.
http://cppcheck.sourceforge.net/

It analyses C++ sourcecode and gives advices on several stuff that compilers often don't recognize (performance, never used variables, variable scope optimizations, not initialized variables, const correctness, pass-by-reference, detecting obsolete functions, ...).

Here is the output it gave me for the current OD source, I'm going to fix some of them.

{l Code}: {l Select All Code}
[\include\Socket.h:53]: (performance) Function parameter 'host' should be passed by reference.
[\include\GameMap.h:260]: (information) Technically the member function 'AstarEntry::fCost' can be const.
[\include\ExampleApplication.h:73]: (warning) Member variable 'ExampleApplication::mCamera' is not initialised in the constructor.
[\include\ExampleApplication.h:73]: (warning) Member variable 'ExampleApplication::mWindow' is not initialised in the constructor.
[\include\ProtectedObject.h:36]: (warning) Member variable 'ProtectedObject<unsignedint>::object' is not initialised in the constructor.
[\include\ProtectedObject.h:36]: (warning) Member variable 'ProtectedObject<long>::object' is not initialised in the constructor.
[\src\Creature.cpp:2281]: (Stil) Variable 'myTile' is assigned a value that is never used
[\src\Creature.cpp:533]: (information) The scope of the variable diceRoll can be reduced
[\src\Creature.cpp:534]: (information) The scope of the variable tempDouble can be reduced
[\src\Creature.cpp:31]: (warning) Member variable 'Creature::color' is not initialised in the constructor.
[\src\Creature.cpp:31]: (warning) Member variable 'Creature::previousPositionTile' is not initialised in the constructor.
[\src\CreatureClass.cpp:3]: (warning) Member variable 'CreatureClass::bedDim1' is not initialised in the constructor.
[\src\CreatureClass.cpp:3]: (warning) Member variable 'CreatureClass::bedDim2' is not initialised in the constructor.
[\src\CreatureClass.cpp:3]: (warning) Member variable 'CreatureClass::coefficientHumans' is not initialised in the constructor.
[\src\CreatureClass.cpp:3]: (warning) Member variable 'CreatureClass::coefficientCorpars' is not initialised in the constructor.
[\src\CreatureClass.cpp:3]: (warning) Member variable 'CreatureClass::coefficientUndead' is not initialised in the constructor.
[\src\CreatureClass.cpp:3]: (warning) Member variable 'CreatureClass::coefficientConstructs' is not initialised in the constructor.
[\src\CreatureClass.cpp:3]: (warning) Member variable 'CreatureClass::coefficientDenizens' is not initialised in the constructor.
[\src\CreatureClass.cpp:3]: (warning) Member variable 'CreatureClass::coefficientAltruism' is not initialised in the constructor.
[\src\CreatureClass.cpp:3]: (warning) Member variable 'CreatureClass::coefficientOrder' is not initialised in the constructor.
[\src\CreatureClass.cpp:3]: (warning) Member variable 'CreatureClass::coefficientPeace' is not initialised in the constructor.
[\src\CreatureClass.cpp:101] -> [\include\CreatureClass.h:39]: (information) Technically the member function 'CreatureClass::isWorker' can be const.
[\src\ExampleFrameListener.cpp:253]: (Stil) Variable 'depth' is not assigned a value
[\src\ExampleFrameListener.cpp:254]: (Stil) Variable 'left' is not assigned a value
[\src\ExampleFrameListener.cpp:494]: (Stil) Variable 'releaseRenderQueueBarrier' is assigned a value that is never used
[\src\ExampleFrameListener.cpp:2726]: (information) The scope of the variable tempR can be reduced
[\src\ExampleFrameListener.cpp:2726]: (information) The scope of the variable tempG can be reduced
[\src\ExampleFrameListener.cpp:2726]: (information) The scope of the variable tempB can be reduced
[\src\ExampleFrameListener.cpp:1465]: (Stil) Found obsolete function 'usleep'. It is recommended that new applications use the 'nanosleep' or 'setitimer' function
[\src\GameMap.cpp:207]: (Stil) Variable 'allNeighborsSameColor' is assigned a value that is never used
[\src\GameMap.cpp:2466]: (information) The scope of the variable tempUnsigned can be reduced
[\src\GameMap.cpp:2496]: (information) The scope of the variable tempUnsigned can be reduced
[\src\GameMap.cpp:31]: (warning) Member variable 'GameMap::me' is not initialised in the constructor.
[\src\GameMap.cpp:31]: (warning) Member variable 'GameMap::miscUpkeepTime' is not initialised in the constructor.
[\src\GameMap.cpp:31]: (warning) Member variable 'GameMap::creatureTurnsTime' is not initialised in the constructor.
[\src\Goal.cpp:28] -> [\include\Goal.h:35]: (information) Technically the member function 'Goal::getName' can be const.
[\src\MapLight.cpp:29]: (warning) Member variable 'MapLight::ogreEntityVisualIndicatorExists' is not initialised in the constructor.
[\src\RadialVector2.cpp:43] -> [\include\RadialVector2.h:15]: (information) Technically the member function 'RadialVector2::directionIsBetween' can be const.
[\src\RenderRequest.cpp:3]: (warning) Member variable 'RenderRequest::turnNumber' is not initialised in the constructor.
[\src\RenderRequest.cpp:3]: (warning) Member variable 'RenderRequest::b' is not initialised in the constructor.
[\src\Room.cpp:15]: (warning) Member variable 'Room::type' is not initialised in the constructor.
[\src\Room.cpp:340] -> [\include\Room.h:52]: (information) Technically the member function 'Room::getType' can be const.
[\src\RoomObject.cpp:29] -> [\include\RoomObject.h:18]: (information) Technically the member function 'RoomObject::getMeshName' can be const.
[\src\RoomPortal.cpp:15]: (warning) Member variable 'RoomPortal::xCenter' is not initialised in the constructor.
[\src\RoomPortal.cpp:15]: (warning) Member variable 'RoomPortal::yCenter' is not initialised in the constructor.
[\src\RoomQuarters.cpp:123]: (information) The scope of the variable xDim can be reduced
[\src\RoomQuarters.cpp:123]: (information) The scope of the variable yDim can be reduced
[\src\RoomQuarters.cpp:123]: (information) The scope of the variable rotationAngle can be reduced
[\src\RoomTreasury.cpp:143] -> [\include\RoomTreasury.h:30]: (information) Technically the member function 'RoomTreasury::getTreasuryTileFullness' can be const.
[\src\Seat.cpp:4]: (warning) Member variable 'Seat::color' is not initialised in the constructor.
[\src\Seat.cpp:4]: (warning) Member variable 'Seat::startingX' is not initialised in the constructor.
[\src\Seat.cpp:4]: (warning) Member variable 'Seat::startingY' is not initialised in the constructor.
[\src\Seat.cpp:146] -> [\include\Seat.h:37]: (information) Technically the member function 'Seat::rawGetNumClaimedTiles' can be const.
[\src\Server.cpp:200]: (Stil) Found obsolete function 'usleep'. It is recommended that new applications use the 'nanosleep' or 'setitimer' function
[\src\Socket.cpp:102]: (performance) Function parameter 's' should be passed by reference.
[\src\Socket.cpp:142]: (performance) Function parameter 'host' should be passed by reference.
[\src\SoundEffectsHelper.cpp:184] -> [\include\SoundEffectsHelper.h:53]: (information) Technically the member function 'SoundEffectsHelper::registerCreatureClass' can be const.
[\src\Tile.cpp:101]: (information) The scope of the variable tempInt can be reduced
[\src\Trap.cpp:10]: (warning) Member variable 'Trap::type' is not initialised in the constructor.
[\src\Trap.cpp:10]: (warning) Member variable 'Trap::exp' is not initialised in the constructor.
[\src\Trap.cpp:121] -> [\include\Trap.h:35]: (information) Technically the member function 'Trap::getType' can be const.
[\src\Trap.cpp:175] -> [\include\Trap.h:42]: (information) Technically the member function 'Trap::getMeshName' can be const.
[\src\TrapCannon.cpp:9]: (warning) Member variable 'TrapCannon::x' is not initialised in the constructor.
[\src\TrapCannon.cpp:9]: (warning) Member variable 'TrapCannon::y' is not initialised in the constructor.
[\src\Weapon.cpp:7]: (warning) Member variable 'Weapon::damage' is not initialised in the constructor.
[\src\Weapon.cpp:7]: (warning) Member variable 'Weapon::range' is not initialised in the constructor.
[\src\Weapon.cpp:7]: (warning) Member variable 'Weapon::defense' is not initialised in the constructor.
[\src\Weapon.cpp:7]: (warning) Member variable 'Weapon::parentCreature' is not initialised in the constructor.
Last edited by StefanP.MUC on 26 Mar 2011, 19:24, edited 1 time in total.
StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby oln » 26 Mar 2011, 12:48

Yeah, nice work.
I ran this on the code myself at some point, but I didn't pursue it any further.
Nothing critical, but there is a bunch of stuff that ought to be fixed.
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 26 Mar 2011, 12:56

Just pushed a rather big commit. The only things left that cppcheck is hinting at are all the not initialized variables in the constructors and the two uses of the obsolete usleep().
StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby MCMic » 27 Mar 2011, 16:21

I'm trying this tool on some of my projects, it says nothing.
What options do it need?

I just did "cppcheck ." in the src folder, I only got some "Checking ./units_unused/arrow.cpp...
40/42 files checked 95% done"
but no errors or warning.
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 27 Mar 2011, 16:29

I only used the GUI version on Windows, it does everything automatically (select files/folder to check and click start).

But if I take a look in the manual on their website running "cppcheck path" should do the trick. This will only give a message if there are things found in the code that are not good. Maybe your code is perfectly fine. ;)
The manual has all the arguments you can pass to the program.
StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 13 Apr 2011, 12:40

Just ran the new cppcheck 1.48 on the latest git code (and pushed the changes). Had a performance enhancements and a "non-& to &" operator fix.

It still has the obsolete usleep() warning (replace to nanosleep()), but I don't know how to fix this on windows, because windows/MingW only provides usleep(). But this is extremly minor, so no need to worry about it (even though it would be nice to fix all warning in the future).
StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby svenskmand » 13 Apr 2011, 14:01

Cool :)
Jamendo.com - The best music store on the net, uses CC licenses.
User avatar
svenskmand
OD Moderator
 
Posts: 1850
Joined: 09 Dec 2009, 00:07
Location: Denmark

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 27 Apr 2011, 10:15

I also fixed the cppcheck warnings for tinygettext now (and some non-critical others).

Now there are only four messages left:
- 2 false style warnings (this is a bug in cppcheck, cppcheck 1.49 will have fixed this according to their bugtracker)
- the 2 usleep()'s (sadly, on Windows there isn't setitimer and nanosleep, not sure if we ever can fix this then)
StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 18 Jun 2011, 18:55

Notice: The new Cppcheck 1.49 doesn't find anything new (so still only the two obsolete usleep() left).
StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 13 Aug 2011, 19:52

I just added a cppcheck project file to the git root (od.cppcheck). Opening this with Cppcheck instantly checks our sources for problems.

This can also be used by new coders for an entry point to development of the game.
StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 15 Aug 2011, 20:09

Cppcheck 1.50 is out. I didn't fix it myself now, because I think most of the code is oln's very new and probably unfinished work (don't want to mess around if you're still working on it). Strangely the usleep() warnings are gone, this could be a bug in cppcheck (I reported it already).

Here's the output:

{l Code}: {l Select All Code}
[source\AIWrapper.cpp:22]: (warning) Member variable 'AIWrapper::player' is not initialized in the constructor.
[source\AIWrapper.cpp:22]: (warning) Member variable 'AIWrapper::seat' is not initialized in the constructor.
[source\AIWrapper.cpp:22]: (warning) Member variable 'AIWrapper::gameMap' is not initialized in the constructor.
[source\AIWrapper.cpp:37]: (warning) Member variable 'AIWrapper::player' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.cpp:37]: (warning) Member variable 'AIWrapper::seat' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.cpp:37]: (warning) Member variable 'AIWrapper::gameMap' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.h:40]: (information) Technically the member function 'AIWrapper::getGameMap' can be const.
[source\AIWrapper.h:41]: (information) Technically the member function 'AIWrapper::getPlayer' can be const.
[source\Goal.cpp:33] -> [source\Goal.h:33]: (information) Technically the member function 'Goal::numSuccessSubGoals' can be const.
[source\Goal.cpp:48] -> [source\Goal.h:37]: (information) Technically the member function 'Goal::numFailureSubGoals' can be const.
[source\ODApplication.cpp:92]: (style) Exception should be caught by reference.
[source\ODApplication.cpp:97]: (style) Exception should be caught by reference.
[source\ODApplication.cpp:117]: (style) Exception should be caught by reference.
[source\ODApplication.cpp:122]: (style) Exception should be caught by reference.
[source\RenderManager.cpp:39]: (warning) Member variable 'RenderManager::viewport' is not initialized in the constructor.
[source\RenderManager.cpp:39]: (warning) Member variable 'RenderManager::shaderGenerator' is not initialized in the constructor.
[dependencies\tinygettext\language.cpp:411]: (style) Variable 'codeset' is assigned a value that is never used
StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby oln » 15 Aug 2011, 20:19

StefanP.MUC {l Wrote}:Cppcheck 1.50 is out. I didn't fix it myself now, because I think most of the code is oln's very new and probably unfinished work (don't want to mess around if you're still working on it). Strangely the usleep() warnings are gone, this could be a bug in cppcheck (I reported it already).

Here's the output:

{l Code}: {l Select All Code}
[source\AIWrapper.cpp:22]: (warning) Member variable 'AIWrapper::player' is not initialized in the constructor.
[source\AIWrapper.cpp:22]: (warning) Member variable 'AIWrapper::seat' is not initialized in the constructor.
[source\AIWrapper.cpp:22]: (warning) Member variable 'AIWrapper::gameMap' is not initialized in the constructor.
[source\AIWrapper.cpp:37]: (warning) Member variable 'AIWrapper::player' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.cpp:37]: (warning) Member variable 'AIWrapper::seat' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.cpp:37]: (warning) Member variable 'AIWrapper::gameMap' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.h:40]: (information) Technically the member function 'AIWrapper::getGameMap' can be const.
[source\AIWrapper.h:41]: (information) Technically the member function 'AIWrapper::getPlayer' can be const.
[source\Goal.cpp:33] -> [source\Goal.h:33]: (information) Technically the member function 'Goal::numSuccessSubGoals' can be const.
[source\Goal.cpp:48] -> [source\Goal.h:37]: (information) Technically the member function 'Goal::numFailureSubGoals' can be const.
[source\ODApplication.cpp:92]: (style) Exception should be caught by reference.
[source\ODApplication.cpp:97]: (style) Exception should be caught by reference.
[source\ODApplication.cpp:117]: (style) Exception should be caught by reference.
[source\ODApplication.cpp:122]: (style) Exception should be caught by reference.
[source\RenderManager.cpp:39]: (warning) Member variable 'RenderManager::viewport' is not initialized in the constructor.
[source\RenderManager.cpp:39]: (warning) Member variable 'RenderManager::shaderGenerator' is not initialized in the constructor.
[dependencies\tinygettext\language.cpp:411]: (style) Variable 'codeset' is assigned a value that is never used

Yeah, most of it is unfinished. The exception can be fixed though.
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 16 Aug 2011, 13:27

OK.

Information from Cppcheck team:
The usleep() message is gone because cppcheck has now checks that are only checked if some specific condition holds. For usleep() this would be if the checked code is strictly POSIX compliant (which ours is not, so usleep isn't considered as "bad" anymore).
StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 11 Dec 2011, 19:10

Cppcheck 1.52 is out (I forget the post about 1.51). It has some new and improved checks that leaded to some new warnings and errors in our code.

Here's the full output. I will fix some (maybe even all) of it tomorow (along with updating AngelScript to the latest version).

{l Code}: {l Select All Code}
[source\AIWrapper.h:53]: (style) inconclusive Technically the member function 'AIWrapper::getGameMap' can be const.
[source\AIWrapper.h:54]: (style) inconclusive Technically the member function 'AIWrapper::getPlayer' can be const.
[source\AIManager.cpp:76]: (warning) Member variable 'AIManager::aiList' is not assigned a value in 'AIManager::operator='
[source\AIWrapper.cpp:132]: (warning) Member variable 'AIWrapper::dungeonTemple' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.cpp:81]: (performance) Possible inefficient checking for 'dt' emptiness.
[source\BaseAI.cpp:22]: (warning) Member variable 'BaseAI::aiType' is not initialized in the constructor.
[source\Client.cpp:31]: (style) C-style pointer casting
[source\Client.cpp:32]: (style) C-style pointer casting
[source\Client.cpp:34]: (style) C-style pointer casting
[source\Client.cpp:419]: (style) C-style pointer casting
[source\Client.cpp:420]: (style) C-style pointer casting
[source\Client.cpp:431]: (style) C-style pointer casting
[source\Client.cpp:432]: (style) C-style pointer casting
[source\Client.cpp:444]: (style) C-style pointer casting
[source\Creature.cpp:612]: (style) C-style pointer casting
[source\Creature.cpp:617]: (style) C-style pointer casting
[source\Creature.cpp:1162]: (style) C-style pointer casting
[source\Creature.cpp:1209]: (style) C-style pointer casting
[source\Creature.cpp:1228]: (style) C-style pointer casting
[source\Creature.cpp:1278]: (style) C-style pointer casting
[source\Creature.cpp:1310]: (style) C-style pointer casting
[source\Creature.cpp:1316]: (style) C-style pointer casting
[source\Creature.cpp:1443]: (style) C-style pointer casting
[source\Creature.h:86]: (style) inconclusive Technically the member function 'Creature::getDefinition' can be const.
[source\GameMap.cpp:474]: (style) C-style pointer casting
[source\GameMap.cpp:995]: (style) C-style pointer casting
[source\GameMap.cpp:1149]: (style) C-style pointer casting
[source\GameMap.cpp:2096]: (style) C-style pointer casting
[source\GameMap.cpp:2113]: (style) C-style pointer casting
[source\GameMap.cpp:2141]: (style) C-style pointer casting
[source\InputManager.cpp:166]: (warning) scanf without field width limits can crash with huge input data
[source\InputManager.cpp:217]: (warning) scanf without field width limits can crash with huge input data
[source\RenderManager.cpp:41]: (warning) Member variable 'RenderManager::gameMap' is not initialized in the constructor.
[source\RenderManager.cpp:41]: (warning) Member variable 'RenderManager::viewport' is not initialized in the constructor.
[source\RenderManager.cpp:41]: (warning) Member variable 'RenderManager::shaderGenerator' is not initialized in the constructor.
[source\RoomQuarters.cpp:22]: (style) C-style pointer casting
[source\RoomQuarters.cpp:30]: (style) C-style pointer casting
[source\RoomQuarters.cpp:32]: (style) C-style pointer casting
[source\RoomQuarters.cpp:38]: (style) C-style pointer casting
[source\RoomQuarters.cpp:40]: (style) C-style pointer casting
[source\RoomQuarters.cpp:41]: (style) C-style pointer casting
[source\RoomQuarters.cpp:43]: (style) C-style pointer casting
[source\RoomTreasury.cpp:25]: (style) C-style pointer casting
[source\RoomTreasury.cpp:27]: (style) C-style pointer casting
[source\Server.cpp:33]: (style) C-style pointer casting
[source\Server.cpp:35]: (style) C-style pointer casting
[source\Server.cpp:36]: (style) C-style pointer casting
[source\Server.cpp:248]: (style) C-style pointer casting
[source\Server.cpp:250]: (style) C-style pointer casting
[source\Server.cpp:327]: (style) C-style pointer casting
[source\Server.cpp:353]: (style) C-style pointer casting
[source\Server.cpp:361]: (style) C-style pointer casting
[source\Server.cpp:407]: (style) C-style pointer casting
[source\Server.cpp:408]: (style) C-style pointer casting
[source\Server.cpp:410]: (style) C-style pointer casting
[source\Tile.cpp:595]: (error) inconclusive Inconclusive: Assigning address of local auto-variable to a function parameter.
[dependencies\tinygettext\language.cpp:411]: (style) Variable 'codeset' is assigned a value that is never used
StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 12 Dec 2011, 17:02

Just pushed the AS update and the cppcheck fixes (some from the AI files are left). Also added a todo about the crasher bug with this semaphore crash in GameEntity.

Here's the current cppcheck output:
{l Code}: {l Select All Code}
[source\AIManager.cpp:76]: (warning) Member variable 'AIManager::aiList' is not assigned a value in 'AIManager::operator='
[source\AIWrapper.cpp:132]: (warning) Member variable 'AIWrapper::dungeonTemple' is not assigned a value in 'AIWrapper::operator='
[source\BaseAI.cpp:22]: (warning) Member variable 'BaseAI::aiType' is not initialized in the constructor.
[source\InputManager.cpp:166]: (warning) scanf without field width limits can crash with huge input data
[source\InputManager.cpp:217]: (warning) scanf without field width limits can crash with huge input data
[source\Tile.cpp:594]: (error) inconclusive Inconclusive: Assigning address of local auto-variable to a function parameter.
[dependencies\tinygettext\language.cpp:411]: (style) Variable 'codeset' is assigned a value that is never used

StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 01 May 2012, 14:58

Here's the current Cppcheck 1.54 output. Most of it is minor or temporary (due to refactoring), and I think the one error is a false-positive (bug in cppcheck). So, nothing to worry about.

{l Code}: {l Select All Code}
[source\Tile.h:142]: (style) inconclusive Technically the member function 'Tile::recieveExp' can be const.
[source\Tile.h:145]: (style) inconclusive Technically the member function 'Tile::getHP' can be const.
[source\Tile.h:142]: (style) inconclusive Technically the member function 'Tile::recieveExp' can be const.
[source\Tile.h:145]: (style) inconclusive Technically the member function 'Tile::getHP' can be const.
[source\AIManager.cpp:76]: (warning) Member variable 'AIManager::gameMap' is not assigned a value in 'AIManager::operator='
[source\AIManager.cpp:76]: (warning) Member variable 'AIManager::aiList' is not assigned a value in 'AIManager::operator='
[source\AIWrapper.cpp:132]: (warning) Member variable 'AIWrapper::gameMap' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.cpp:132]: (warning) Member variable 'AIWrapper::player' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.cpp:132]: (warning) Member variable 'AIWrapper::seat' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.cpp:132]: (warning) Member variable 'AIWrapper::dungeonTemple' is not assigned a value in 'AIWrapper::operator='
[source\Player.h:48]: (style) inconclusive Technically the member function 'Player::getCreaturesInHand' can be const.
[source\Player.h:49]: (style) inconclusive Technically the member function 'Player::getNewRoomType' can be const.
[source\Player.h:48]: (style) inconclusive Technically the member function 'Player::getCreaturesInHand' can be const.
[source\Player.h:49]: (style) inconclusive Technically the member function 'Player::getNewRoomType' can be const.
[source\Creature.h:71]: (style) inconclusive Technically the member function 'Creature::getHP' can be const.
[source\Creature.h:71]: (style) inconclusive Technically the member function 'Creature::getHP' can be const.
[source\BaseAI.cpp:22]: (warning) Member variable 'BaseAI::aiType' is not initialized in the constructor.
[source\Weapon.h:54]: (style) inconclusive Technically the member function 'Weapon::recieveExp' can be const.
[source\Weapon.h:56]: (style) inconclusive Technically the member function 'Weapon::getHP' can be const.
[source\Weapon.h:54]: (style) inconclusive Technically the member function 'Weapon::recieveExp' can be const.
[source\Weapon.h:56]: (style) inconclusive Technically the member function 'Weapon::getHP' can be const.
[source\Creature.cpp:2058] -> [source\Creature.h:143]: (style) inconclusive Technically the member function 'Creature::getHasVisualDebuggingEntities' can be const.
[source\Director.cpp:7]: (warning) Member variable 'Director::isServer' is not initialized in the constructor.
[source\Director.cpp:7]: (warning) Member variable 'Director::applicationModeId' is not initialized in the constructor.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::inputManager' is not initialized in the constructor.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::previousTurn' is not initialized in the constructor.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::creatureSceneNode' is not initialized in the constructor.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::roomSceneNode' is not initialized in the constructor.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::fieldSceneNode' is not initialized in the constructor.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::lightSceneNode' is not initialized in the constructor.
[source\RoomObject.h:22]: (style) inconclusive Technically the member function 'RoomObject::recieveExp' can be const.
[source\RoomObject.h:25]: (style) inconclusive Technically the member function 'RoomObject::getHP' can be const.
[source\MissileObject.h:30]: (style) inconclusive Technically the member function 'MissileObject::recieveExp' can be const.
[source\MissileObject.h:33]: (style) inconclusive Technically the member function 'MissileObject::getHP' can be const.
[source\MissileObject.h:30]: (style) inconclusive Technically the member function 'MissileObject::recieveExp' can be const.
[source\MissileObject.h:33]: (style) inconclusive Technically the member function 'MissileObject::getHP' can be const.
[source\MovableGameEntity.cpp:10]: (warning) Member variable 'MovableGameEntity::shortDistance' is not initialized in the constructor.
[source\Room.cpp:558] -> [source\Room.h:85]: (style) inconclusive Technically the member function 'Room::recieveExp' can be const.
[source\Tile.cpp:776] -> [source\Tile.h:97]: (style) inconclusive Technically the member function 'Tile::getMarkedForDigging' can be const.
[source\Tile.cpp:790] -> [source\Tile.h:98]: (style) inconclusive Technically the member function 'Tile::isMarkedForDiggingByAnySeat' can be const.
[source\Tile.cpp:1035] -> [source\Tile.h:115]: (style) inconclusive Technically the member function 'Tile::scaleDigRate' can be const.
[dependencies\tinygettext\language.cpp:411]: (style) Variable 'codeset' is assigned a value that is never used
[source\GameMap.cpp:630] -> [source\GameMap.h:92]: (style) inconclusive Technically the member function 'GameMap::numClassDescriptions' can be const.
[source\GameMap.cpp:1965] -> [source\GameMap.h:107]: (style) inconclusive Technically the member function 'GameMap::numRooms' can be const.
[source\GameMap.cpp:2083] -> [source\GameMap.h:122]: (style) inconclusive Technically the member function 'GameMap::numTraps' can be const.
[source\GameMap.cpp:2186] -> [source\GameMap.h:133]: (style) inconclusive Technically the member function 'GameMap::numMapLights' can be const.
[source\GameMap.cpp:2339] -> [source\GameMap.h:153]: (style) inconclusive Technically the member function 'GameMap::getNumWinningSeats' can be const.
[source\GameMap.cpp:2457] -> [source\GameMap.h:166]: (style) inconclusive Technically the member function 'GameMap::numMissileObjects' can be const.
[source\GameMap.cpp:138]: (error) Same iterator is used with both constTiles and tiles
[source\InputManager.cpp:171]: (warning) scanf without field width limits can crash with huge input data
[source\InputManager.cpp:224]: (warning) scanf without field width limits can crash with huge input data
StefanP.MUC
 

Re: cppcheck - Sourcecode analysis

Postby StefanP.MUC » 04 Jul 2012, 16:47

Cppcheck 1.55 results on latest development branch (already without the ones I just fixed). Most of them are missing initializations because of work-in-progress classes. The one performance and I think the one error, too, notices are false positives by cppcheck. So, nothing to worry about.

{l Code}: {l Select All Code}
[source\Director.cpp:7]: (warning) Member variable 'Director::isServer' is not initialized in the constructor.
[source\Director.cpp:7]: (warning) Member variable 'Director::applicationModeId' is not initialized in the constructor.
[dependencies\tinygettext\language.cpp:411]: (style) Variable 'codeset' is assigned a value that is never used
[source\AIManager.cpp:77]: (warning) Member variable 'AIManager::gameMap' is not assigned a value in 'AIManager::operator='
[source\AIManager.cpp:77]: (warning) Member variable 'AIManager::aiList' is not assigned a value in 'AIManager::operator='
[source\AIWrapper.cpp:132]: (warning) Member variable 'AIWrapper::gameMap' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.cpp:132]: (warning) Member variable 'AIWrapper::player' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.cpp:132]: (warning) Member variable 'AIWrapper::seat' is not assigned a value in 'AIWrapper::operator='
[source\AIWrapper.cpp:132]: (warning) Member variable 'AIWrapper::dungeonTemple' is not assigned a value in 'AIWrapper::operator='
[source\BaseAI.cpp:22]: (warning) Member variable 'BaseAI::aiType' is not initialized in the constructor.
[source\Field.cpp:14]: (performance) Variable 'name' is assigned in constructor body. Consider to perform initalization in initialization list.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::inputManager' is not initialized in the constructor.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::previousTurn' is not initialized in the constructor.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::creatureSceneNode' is not initialized in the constructor.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::roomSceneNode' is not initialized in the constructor.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::fieldSceneNode' is not initialized in the constructor.
[source\GameContext.cpp:9]: (warning) Member variable 'GameContext::lightSceneNode' is not initialized in the constructor.
[source\GameMap.cpp:139]: (error) Same iterator is used with both constTiles and tiles
[source\InputManager.cpp:171]: (warning) scanf without field width limits can crash with huge input data
[source\InputManager.cpp:224]: (warning) scanf without field width limits can crash with huge input data
[source\MovableGameEntity.cpp:10]: (warning) Member variable 'MovableGameEntity::shortDistance' is not initialized in the constructor.
StefanP.MUC
 

Who is online

Users browsing this forum: No registered users and 1 guest