Skip to content

Fix 3 uninitialized variable accesses and some optimizations - #38

Closed
DanWin wants to merge 1 commit into
audacity:masterfrom
DanWin:master
Closed

DanWin wants to merge 1 commit into
audacity:masterfrom
DanWin:master

Conversation

@DanWin

@DanWin DanWin commented Apr 29, 2015

Copy link
Copy Markdown
Contributor

No description provided.

@Paul-Licameli

Copy link
Copy Markdown
Collaborator

In ToolDock and TimeTrack, what was the real intent? Are you sure those fixes are the correct ones?

@DanWin

DanWin commented Apr 29, 2015

Copy link
Copy Markdown
Contributor Author

The affected code in ToolDock and TimeTrack wasn't touched in years, we can only guess what originally was intended.
And concerning the other fixes, I double checked the code and did a test run with valgrind. Everything works fine for me. I'm pretty sure, those are correct.

Comment thread src/widgets/Grabber.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure what this is needed???

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an optimization. Initialization lists are a little bit faster than assigning the value in the constructor body. And as one value already uses the initialization list, I simply moved that one over there too. ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried this in g++ with -O3 specified:

class inconstructor
{
public:
   inconstructor(int parm1)
   {
      mParm = parm1;
   }

public:
   int mParm;
};

class ininitializer
{
public:
   ininitializer(int parm1)
   :  mParm(parm1)
   {
   }

public:
   int mParm;
};

inconstructor tryc(123);
ininitializer tryi(456);

And here is what the compiler produced:

   .file "t.cpp"
   .section .text.startup,"x"
   .p2align 4,,15
   .def  _GLOBAL__sub_I_tryc; .scl  3; .type 32;   .endef
   .seh_proc   _GLOBAL__sub_I_tryc
_GLOBAL__sub_I_tryc:
.LFB7:
   .seh_endprologue
   movl  $123, tryc(%rip)
   movl  $456, tryi(%rip)
   ret
   .seh_endproc
   .section .ctors,"w"
   .align 8
   .quad _GLOBAL__sub_I_tryc
   .globl   tryi
   .bss
   .align 4
tryi:
   .space 4
   .globl   tryc
   .align 4
tryc:
   .space 4
   .ident   "GCC: (GNU) 4.9.2"

Looks about the same to me...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give it a read in a bit, but here's one using an object:

class morecomplex
{
public:
   morecomplex()
   {
   }

   morecomplex(int parm)
   {
      mParm = parm;
   }
public:
   int mParm;
};

class inconstructor
{
public:
   inconstructor(morecomplex parm1)
   {
      mParm = parm1;
   }

public:
   morecomplex mParm;
};

class ininitializer
{
public:
   ininitializer(morecomplex parm1)
   :  mParm(parm1)
   {
   }

public:
   morecomplex mParm;
};

extern morecomplex trycc;
extern morecomplex tryci;
inconstructor tryc(trycc);
ininitializer tryi(tryci);

And the results:

        .file   "t.cpp"
        .section        .text.startup,"x"
        .p2align 4,,15
        .def    _GLOBAL__sub_I_tryc;    .scl    3;      .type   32;     .endef
        .seh_proc       _GLOBAL__sub_I_tryc
_GLOBAL__sub_I_tryc:
.LFB13:
        .seh_endprologue
        movq    .refptr.trycc(%rip), %rax
        movl    (%rax), %eax
        movl    %eax, tryc(%rip)
        movq    .refptr.tryci(%rip), %rax
        movl    (%rax), %eax
        movl    %eax, tryi(%rip)
        ret
        .seh_endproc
        .section        .ctors,"w"
        .align 8
        .quad   _GLOBAL__sub_I_tryc
        .globl  tryi
        .bss
        .align 4
tryi:
        .space 4
        .globl  tryc
        .align 4
tryc:
        .space 4
        .ident  "GCC: (GNU) 4.9.2"
        .section        .rdata$.refptr.tryci, "dr"
        .globl  .refptr.tryci
        .linkonce       discard
.refptr.tryci:
        .quad   tryci
        .section        .rdata$.refptr.trycc, "dr"
        .globl  .refptr.trycc
        .linkonce       discard
.refptr.trycc:
        .quad   trycc

Again, I haven't yet read the article at the provided link yet, but seems to me that, so far, they are the same.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried it with an even more complex "morecomplex" class:

class morecomplex
{
public:
   morecomplex()
   :  mParm(0),
      sss({2, 3, 4.f, 9.0})
   {
   }

   morecomplex(int parm)
   {
      mParm = parm;
   }
public:
   int mParm;
   char buffer[1234];
   struct
   {
      int a;
      int b;
      float f;
      double d;
   } sss;
};

And the results were exactly the same again. Weird...wonder why the guys results were so much better...maybe something to do with templates?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That documentation is pretty old, might be that compilers are a lot smarter than they were back when that document was written… I guess it is not an optimization then, only a style change.
But still, cppcheck suggests to change it.

@JamesCrook

Copy link
Copy Markdown
Contributor

My mistake, it is a pull request, not just a commit. Rejected in its current form. Dan, come on over to audacity-devel e-mail list and we can talk about style in audacity and what an acceptable pull request would need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants