cppcheck output

cppcheck output

Postby KroArtem » 26 Jan 2013, 23:04

Good evening all,
just wanted to look a bit at M&MS code and run it through cppcheck, here is the output:
{l Code}: {l Select All Code}
[src/Block.cpp:31]: (warning) Member variable 'Block::inAirSave' is not initialized in the constructor.
[src/Block.cpp:31]: (warning) Member variable 'Block::xVelSave' is not initialized in the constructor.
[src/Block.cpp:31]: (warning) Member variable 'Block::yVelSave' is not initialized in the constructor.
[src/Block.cpp:31]: (warning) Member variable 'Block::xVelBaseSave' is not initialized in the constructor.
[src/Block.cpp:31]: (warning) Member variable 'Block::yVelBaseSave' is not initialized in the constructor.
[src/Functions.cpp:718]: (warning) scanf without field width limits can crash with huge input data
[src/GUIObject.cpp:263]: (style) The scope of the variable 'wid' can be reduced
[src/GUITextArea.cpp:245]: (style) The scope of the variable 'cline' can be reduced
[src/InputManager.cpp:299]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant.
[src/MD5.h:25]: (style) The class 'Md5' does not have a constructor.
[src/LevelEditor.cpp:2453]: (style) C-style pointer casting
[src/LevelEditor.cpp:2474]: (style) C-style pointer casting
[src/LevelEditor.cpp:2483]: (style) C-style pointer casting
[src/StatisticsManager.cpp:138]: (warning) scanf without field width limits can crash with huge input data
[src/libs/findlocale/findlocale.c:420]: (style) Variable 'sub_lang' is assigned a value that is never used
[src/libs/tinygettext/dictionary_manager.cpp:33]: (performance) Function parameter 'rhs' should be passed by reference.
[src/libs/tinygettext/dictionary_manager.cpp:237]: (style) Copy 'auto_ptr' pointer to another do not create two equal objects since one has lost its ownership of the pointer.
[src/libs/tinygettext/dictionary_manager.cpp:120]: (performance) Prefer prefix ++/-- operators for non-primitive types.
[src/libs/tinygettext/language.cpp:421]: (style) Variable 'codeset' is assigned a value that is never used
[src/libs/tinygettext/po_parser.cpp:225]: (performance) Function parameter 'rhs' should be passed by reference.


If it's not hard for you to answer me, please tell how to fix such warnings in these cases? Let's forget about src/lib folder as it's a bad idea to fix things in libs and don't return it back to these libs's developers. Also let's not think about scanf being able to crash with huge input data. What about missing initializing in Block constructor? Why don't you init those values?

P.S. btw, it's cool that this project has so little amount of warnings. ;)
Last edited by KroArtem on 27 Jan 2013, 14:48, edited 1 time in total.
KroArtem
 
Posts: 375
Joined: 26 Aug 2010, 19:04

Re: cppcheck output

Postby Edward_Lii » 27 Jan 2013, 13:29

Hello KroArtem,

KroArtem {l Wrote}:What's about missing initializing in Block constructor? Why don't you init those values?

I simply forgot to initialise them in the constructor. :p
Nothing could have gone wrong in this case, since the save variables are only read when there's a saved state.
Nevertheless I have fixed this in svn rev. 558 by initialising them in the same way as their normal variable counterpart.

As for the other warnings, I don't see anything alarming/"worth" fixing.
The problem I have with a lot of style warnings is that fixing them sometimes reduces the readability.
Besides, investing time in code that works and might even be rewritten/changed at some point in the future is unnecessary IMHO.

The performance warning can be fixed quite easily, just like the scanf warnings.
I will probably commit fixes for them along with my next commit. ;)

KroArtem {l Wrote}:P.S. btw, it's cool that this project has so little amount of warnings. ;)

Although it isn't highest on our priority list, we do our best to keep warnings at a minimum.
From,
Edward_Lii
User avatar
Edward_Lii
MnMS Moderator
 
Posts: 777
Joined: 20 Dec 2010, 16:46

Re: cppcheck output

Postby KroArtem » 27 Jan 2013, 14:52

Ok, thanks a lot for your explanation.
KroArtem
 
Posts: 375
Joined: 26 Aug 2010, 19:04

Who is online

Users browsing this forum: No registered users and 1 guest