Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Uninitialized class members.
| Uninitialized class members. [message #15725] |
Tue, 06 May 2008 17:31  |
Novo
Messages: 1431 Registered: December 2006
|
Ultimate Contributor |
|
|
There are many uninitialized class members in U++. Valgrind complains about them a lot.
I’ve attached a diff file, which fixes several of them.
If you are thinking such fixes are important to U++ I can submit more …
Regards,
Novo
|
|
|
|
| Re: Uninitialized class members. [message #15728 is a reply to message #15725] |
Tue, 06 May 2008 19:44   |
 |
mirek
Messages: 14290 Registered: November 2005
|
Ultimate Member |
|
|
Not sure what valgrind really tests...
-ScrollBar::ScrollBar() {
+ScrollBar::ScrollBar() :
+style(NULL)
+{
"style" is initialized by SetStyle call in constructor.
-TreeCtrl::TreeCtrl()
+TreeCtrl::TreeCtrl() :
+ selectcount(0)
"selectcount" is initialized by Clear call in constructor.
Stopped there.... Finding them in .diff is too time consuming, maybe you could just post me the list of problems instead of .diff?
Mirek
P.S.: Do not get me wrong, valgrind is perhaps a good idea! But looks like it produces some false alarms too...
[Updated on: Tue, 06 May 2008 19:45] Report message to a moderator
|
|
|
|
|
|
| Re: Uninitialized class members. [message #15738 is a reply to message #15735] |
Tue, 06 May 2008 21:27   |
 |
mirek
Messages: 14290 Registered: November 2005
|
Ultimate Member |
|
|
| Novo wrote on Tue, 06 May 2008 14:34 |
| luzr wrote on Tue, 06 May 2008 13:44 | Not sure what valgrind really tests...
-ScrollBar::ScrollBar() {
+ScrollBar::ScrollBar() :
+style(NULL)
+{
"style" is initialized by SetStyle call in constructor.
|
Valgrind:
==30773== at 0x5A10E3: Upp::ScrollBar::SetStyle(Upp::ScrollBar::Style const&)
==30773== by 0x5DDB88: Upp::ScrollBar::ScrollBar() (in /export/home/ssikorsk/
==30773== by 0x5F4699: Upp::ColumnList::ColumnList() (in /export/home/ssikors
==30773== by 0x5F4A87: Upp::FileList::FileList() (in /export/home/ssikorsk/dv
==30773== by 0x44A7D3: WorkspaceWork::WorkspaceWork() (in /export/home/ssikor
==30773== by 0x45C1DB: Ide::Ide() (in /export/home/ssikorsk/dvlp/upp/svn/upp/
==30773== by 0x482D8C: GuiMainFn_() (in /export/home/ssikorsk/dvlp/upp/svn/up
==30773== by 0x484171: main (in /export/home/ssikorsk/dvlp/upp/svn/upp/out/GC
==30773==
Code:
ScrollBar& ScrollBar::SetStyle(const Style& s)
{
if(style != &s) {
style = &s;
RefreshLayout();
Refresh();
}
return *this;
}
That "if(style != &s)" looks very suspicious to me ...
| Quote: |
-TreeCtrl::TreeCtrl()
+TreeCtrl::TreeCtrl() :
+ selectcount(0)
"selectcount" is initialized by Clear call in constructor.
|
Valgrind:
==31285== at 0x672D10: Upp::TreeCtrl::Dirty(int) (in /export/home/ssikorsk/dv
==31285== by 0x67545A: Upp::TreeCtrl::Clear() (in /export/home/ssikorsk/dvlp/
==31285== by 0x6756A8: Upp::TreeCtrl::TreeCtrl() (in /export/home/ssikorsk/dv
==31285== by 0x6142BF: Upp::HelpWindow::HelpWindow() (in /export/home/ssikors
==31285== by 0x42EE02: TopicCtrl::TopicCtrl() (in /export/home/ssikorsk/dvlp/
==31285== by 0x45C91F: Ide::Ide() (in /export/home/ssikorsk/dvlp/upp/svn/upp/
==31285== by 0x482D8C: GuiMainFn_() (in /export/home/ssikorsk/dvlp/upp/svn/up
==31285== by 0x484171: main (in /export/home/ssikorsk/dvlp/upp/svn/upp/out/GC
==31285==
Code:
void TreeCtrl::Clear()
{
item.Clear();
item.Add();
item[0].linei = -1;
item[0].parent = -1;
item[0].canopen = true;
freelist = -1;
Dirty();
cursor = anchor = -1;
selectcount = 0;
}
Dirty() is called before initialization of select count.
| Quote: |
Stopped there.... Finding them in .diff is too time consuming, maybe you could just post me the list of problems instead of .diff?
|
I can post either diff or results of valgrind processing, which you can produce yourself ...
| Quote: |
P.S.: Do not get me wrong, valgrind is perhaps a good idea! But looks like it produces some false alarms too...
|
As you can see from examples above, valgrind is not giving false alarms. 
|
OK, thanks for clarification, you are right (and I am wrong, once again 
Mirek
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Uninitialized class members. [message #15751 is a reply to message #15748] |
Wed, 07 May 2008 04:10   |
Novo
Messages: 1431 Registered: December 2006
|
Ultimate Contributor |
|
|
| mdelfede wrote on Tue, 06 May 2008 17:18 | It would be quite interesting to integrate Valgrind inside the ide....
Max
|
That would be useful. Especially because there is no adequate GUI tool for valgrind at the moment. I've been using valkyrie, which is QT-based, but it doesn't work with valgrind 3.3.0. vim is pretty good in handling of valgrind's output (as usual).
I'd like to mention that valgrind is just a framework. I was running a tool called memcheck, which is based on valgrind. There are other valgrind-based tools. Most popular beside memcheck are callgrind and helgrind.
memcheck can produce XML output. So, the only thing left is to parse that XML and put data into a grid or a tree.
There is a cool example of GUI for callgrind called kcachegrind.
Regards,
Novo
[Updated on: Wed, 07 May 2008 04:27] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
| Re: Uninitialized class members. [message #15774 is a reply to message #15770] |
Wed, 07 May 2008 17:38   |
Novo
Messages: 1431 Registered: December 2006
|
Ultimate Contributor |
|
|
| luzr wrote on Wed, 07 May 2008 10:32 |
That the output is mixed (normal output from the app and valgrind output). Same as with gdb.
|
Options below could be useful ...
--log-fd=<number> log messages to file descriptor [2=stderr]
--log-file=<file> log messages to <file>
--xml=yes all output is in XML (some tools only)
Regards,
Novo
[Updated on: Wed, 07 May 2008 17:42] Report message to a moderator
|
|
|
|
| Re: Uninitialized class members. [message #15775 is a reply to message #15756] |
Wed, 07 May 2008 17:40   |
Novo
Messages: 1431 Registered: December 2006
|
Ultimate Contributor |
|
|
| luzr wrote on Wed, 07 May 2008 03:57 |
| mdelfede wrote on Tue, 06 May 2008 17:18 | It would be quite interesting to integrate Valgrind inside the ide....
Max
|
Yep, I already started checking this 
|
Could you please also check on integration of callgrind?

Regards,
Novo
[Updated on: Wed, 07 May 2008 17:40] Report message to a moderator
|
|
|
|
|
|
|
|
| Re: Uninitialized class members. [message #15788 is a reply to message #15777] |
Wed, 07 May 2008 22:47   |
 |
mirek
Messages: 14290 Registered: November 2005
|
Ultimate Member |
|
|
-ScrollBar::ScrollBar() {
+ScrollBar::ScrollBar()
+: style(NULL)
+, pagepos(0)
+, pagesize(0)
+, totalsize(0)
+{
minthumb = 16;
- pagepos = pagesize = totalsize = 0;
linesize = 1;
?
Same for ArrayCtrl, RichTextView, TopWindow, Ide, Browser....
Mirek
[Updated on: Wed, 07 May 2008 22:54] Report message to a moderator
|
|
|
|
| Re: Uninitialized class members. [message #15792 is a reply to message #15788] |
Wed, 07 May 2008 23:05   |
Novo
Messages: 1431 Registered: December 2006
|
Ultimate Contributor |
|
|
| luzr wrote on Wed, 07 May 2008 16:47 |
-ScrollBar::ScrollBar() {
+ScrollBar::ScrollBar()
+: style(NULL)
+, pagepos(0)
+, pagesize(0)
+, totalsize(0)
+{
minthumb = 16;
- pagepos = pagesize = totalsize = 0;
linesize = 1;
?
Same for ArrayCtrl, RichTextView, TopWindow, Ide, Browser....
Mirek
|
I personally would move all initialization of members into initialization lists, if I understand you correctly.
I traced only several classes. And it took me two or three hours to understand what is wrong with ArrayCtrl. It is just easier to use initialization lists from very beginning.
BTW, helgrind doesn't complain about TheIDE.
Regards,
Novo
[Updated on: Wed, 07 May 2008 23:08] Report message to a moderator
|
|
|
|
| Re: Uninitialized class members. [message #15799 is a reply to message #15770] |
Thu, 08 May 2008 00:06   |
mdelfede
Messages: 1310 Registered: September 2007
|
Ultimate Contributor |
|
|
| luzr wrote on Wed, 07 May 2008 16:32 |
| mdelfede wrote on Wed, 07 May 2008 08:20 |
| luzr wrote on Wed, 07 May 2008 09:57 |
| mdelfede wrote on Tue, 06 May 2008 17:18 | It would be quite interesting to integrate Valgrind inside the ide....
Max
|
Yep, I already started checking this 
Anyway, right now I see (as usual the problem with output in console apps...
Mirek
|
Which problem ?
Max
|
That the output is mixed (normal output from the app and valgrind output). Same as with gdb.
But now thinking about it, maybe this is what error output is for, right?
Mirek
|
Uhmmmm.... I don't know, but I guess there should be a way to redirect GDB/Valgrind output to a different stream than app output... or, you could attach user app output to a different stream than stdout/stderr.
I'll investigate that one, maybe 
Max
|
|
|
|
|
|
| Re: Uninitialized class members. [message #15804 is a reply to message #15792] |
Thu, 08 May 2008 01:00   |
 |
mirek
Messages: 14290 Registered: November 2005
|
Ultimate Member |
|
|
| Novo wrote on Wed, 07 May 2008 17:05 |
| luzr wrote on Wed, 07 May 2008 16:47 |
-ScrollBar::ScrollBar() {
+ScrollBar::ScrollBar()
+: style(NULL)
+, pagepos(0)
+, pagesize(0)
+, totalsize(0)
+{
minthumb = 16;
- pagepos = pagesize = totalsize = 0;
linesize = 1;
?
Same for ArrayCtrl, RichTextView, TopWindow, Ide, Browser....
Mirek
|
I personally would move all initialization of members into initialization lists, if I understand you correctly.
|
OK, I will be thinking about it, although I do not find it particulary atractive... Anyway, for now, I just wanted to clarify the problem:)
Mirek
|
|
|
|
| Re: Uninitialized class members. [message #15808 is a reply to message #15804] |
Thu, 08 May 2008 05:37   |
Novo
Messages: 1431 Registered: December 2006
|
Ultimate Contributor |
|
|
| luzr wrote on Wed, 07 May 2008 19:00 | OK, I will be thinking about it, although I do not find it particulary atractive... Anyway, for now, I just wanted to clarify the problem:)
Mirek
|
The problem is that when you want to run valgrind on TheIDE to understand why it is crashing in release build, you see thousands of messages about using uninitialized memory.
It is just impossible to find something useful among them. Each of them can be a problem.
And of course, there are other concerns ...
Regards,
Novo
|
|
|
|
|
|
| Re: Uninitialized class members. [message #15828 is a reply to message #15809] |
Fri, 09 May 2008 04:37   |
Novo
Messages: 1431 Registered: December 2006
|
Ultimate Contributor |
|
|
| luzr wrote on Thu, 08 May 2008 02:00 | I think the question was whether valgrind detected a problem in ArrayCtrl (and others) when initialization was in constructor body vs in initializer list.
|
Sorry, I misunderstood you.
Yes, it can detect that. If an uninitialized variable was used in an arithmetic expression, and that expression was used in a logical expression after that, you will be warned. Actually, it is really hard to figure out which exactly variable was that. It is much easier to put all members onto initialization list.
valgrind is very important tool to me, and I'd like to see U++ valgrind-frendly, and I'm ready to help. 
Besides, it helps find bugs. 
Regards,
Novo
[Updated on: Fri, 09 May 2008 04:57] Report message to a moderator
|
|
|
|
| Re: Uninitialized class members. [message #15841 is a reply to message #15828] |
Sun, 11 May 2008 18:01   |
 |
mirek
Messages: 14290 Registered: November 2005
|
Ultimate Member |
|
|
| Novo wrote on Thu, 08 May 2008 22:37 |
| luzr wrote on Thu, 08 May 2008 02:00 | I think the question was whether valgrind detected a problem in ArrayCtrl (and others) when initialization was in constructor body vs in initializer list.
|
Sorry, I misunderstood you.
Yes, it can detect that. If an uninitialized variable was used in an arithmetic expression, and that expression was used in a logical expression after that, you will be warned. Actually, it is really hard to figure out which exactly variable was that. It is much easier to put all members onto initialization list.
valgrind is very important tool to me, and I'd like to see U++ valgrind-frendly, and I'm ready to help. 
Besides, it helps find bugs. 
|
Well, I believe theide and U++ is now quite valgrind friendly.
Anyway, I am seeing a lot of "invalid read" entries, but none seems to originate from U++ code (they seem to be "ld", "glibc" and "gtk" issues). What to think about it?
(Of course, valgrind reports a lot of leaks, but that is the same problem IMO; there should be no leaks in U++ code).
Mirek
|
|
|
|
| Re: Uninitialized class members. [message #15846 is a reply to message #15841] |
Sun, 11 May 2008 20:43   |
Novo
Messages: 1431 Registered: December 2006
|
Ultimate Contributor |
|
|
| luzr wrote on Sun, 11 May 2008 12:01 | Well, I believe theide and U++ is now quite valgrind friendly.
|
Thank you very much!
| Quote: |
Anyway, I am seeing a lot of "invalid read" entries, but none seems to originate from U++ code (they seem to be "ld", "glibc" and "gtk" issues). What to think about it?
|
The is nothing you can do about these "ld", "glibc" and "gtk" issues. Valgrind allows you to provide a suppression file. Suppressions can be generated by valgrind automatically (in interactive mode).
I personally never use valgrind without a customized suppression file.
| Quote: |
(Of course, valgrind reports a lot of leaks, but that is the same problem IMO; there should be no leaks in U++ code).
|
It depend on what you call a leak. As I remember, valgrind reports a lot of "potentially lost memory". That usually means that there is non-freed memory on application exit. People usually do not care about that memory because their application is going to stop working anyway, but valgrind does.
These "memory leaks" are usually fixed by eliminating static objects (like strings) and registering memory pools cleanups with atexit().
I'll take a look at that when I get a chance.
Thank you for integrating TheIDE with valgrind again!
Regards,
Novo
[Updated on: Sun, 11 May 2008 20:43] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Tue Apr 28 17:17:41 GMT+2 2026
Total time taken to generate the page: 0.01328 seconds
|