Author Topic: Possible problems in keybinder?  (Read 7625 times)

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
Possible problems in keybinder?
« on: March 25, 2006, 10:51:40 pm »
While compiling the recent revision I noticed a warning:
Quote
keybinder.cpp: In member function `void wxKeyConfigPanel::OnAssignKey(wxCommandE                             
vent&)':
keybinder.cpp:2234: warning: 'n' might be used uninitialized in this function
The corresponding lines of the sourcode are:
Code
	if (m_pCurrCmd) {
wxKeyBind tmp(m_pKeyField->GetValue());
int n;

#ifdef __WXDEBUG__
bool bind = m_pCurrCmd->IsBindTo(tmp, &n);
wxASSERT_MSG(bind, wxT("the m_pCurrCmd variable should be NULL then..."));
#endif // to avoid warnings in release mode

m_pCurrCmd->RemoveShortcut(n);
}
I don't know what this code should do - I simply don't understand it. But if __WXDEBUG__ is not defined the call to wxCmd::RemoveShortcut uses an uninitialized value. I don't think that this is should be done.

And in wxCmd::RemoveShortcut I suspect the next problem:
Code
	void RemoveShortcut(int n) {
for (int i=n; i < m_nShortcuts; i++) // shift array left
m_keyShortcut[i] = m_keyShortcut[i+1];
m_nShortcuts--;
Update();
}
This looks like a buffer overflow because there should be m_nShortcuts elements in the array - but in this part of the code the element with *index* m_nShortcuts is accessed...
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Possible problems in keybinder?
« Reply #1 on: March 25, 2006, 10:56:41 pm »
I don't know the code either, maybe just the asset should be between the ifdefs, as it is now it is certainly wrong.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2773
Re: Possible problems in keybinder?
« Reply #2 on: March 26, 2006, 05:20:24 am »
While compiling the recent revision I noticed a warning:
keybinder.cpp:2234: warning: 'n' might be used uninitialized in this function

thanks, I'll fix this stuff.

How did you get the warning msg. I've got "Enable All Compiler Warnings" turn on. and I can't get the msg.

gcc version 3.4.4 (mingw special)

thanks
pecan

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
Re: Possible problems in keybinder?
« Reply #3 on: March 26, 2006, 11:20:27 am »
I'm using gcc 3.4.5 on Linux and added -Wall as command-line parameter. Then I got this warning. Maybe gcc 3.4.4 did not see this because of the preprocessor macros? Or maybe I just had not defined __WXDEBUG__?

Maybe I'll compile Code::Blocks with icc again - this compiler usually finds more this problems and prints warnings etc. that gcc does.
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.

Offline yop

  • Regular
  • ***
  • Posts: 387
Re: Possible problems in keybinder?
« Reply #4 on: March 26, 2006, 12:12:24 pm »
Maybe I'll compile Code::Blocks with icc again - this compiler usually finds more this problems and prints warnings etc. that gcc does.
It prints tons of remarks, even for the simplest things that we all do. This compiler, though I just love it, can be *really* strict. But it would be a good thing to pass C::B through this one before the next release and hand out the results to the devs. I was even thinking to run it through vtune (if someone could get me some time off my job, I promise I will :lol:), but it would take some time to setup the testing environment and "decode" the results.
Life would be so much easier if we could just look at the source code.

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
Re: Possible problems in keybinder?
« Reply #5 on: March 26, 2006, 03:45:02 pm »
Well, I fear that no one really wants to do this. I just compiled Code::Blocks (with contrib-plugins) using icc with the linux make-system and I redirected all warnings and remarks to a file (thus the file contains all warnings and remarks but not the command-line). This file is about 4.3MB big  :o
Anyway, most of this remarks and warnings can surely be ignored without any risk and there are a lot of warnings about command-line parameters that icc doesn't understand (like -ffast-math oder -Winvalid-pch). That makes the file bigger as it has to be. But finding important warnings/remarks (if there are any!) in this huge file will be terrible. I'm not sure if anyone wants to do this...  8)
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.

Offline yop

  • Regular
  • ***
  • Posts: 387
Re: Possible problems in keybinder?
« Reply #6 on: March 26, 2006, 07:29:07 pm »
This file is about 4.3MB big  :o
Doesn't even worth to try then. You can play a lot with the level of detail you want in the icc output, but I don't know if it's worth the efford.
Life would be so much easier if we could just look at the source code.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Possible problems in keybinder?
« Reply #7 on: March 26, 2006, 07:35:31 pm »
[...] there are a lot of warnings about command-line parameters that icc doesn't understand (like -ffast-math oder -Winvalid-pch).
You could "grep off" these lines and similar (not important things) and see what's remaining, maybe.
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ