potentially uninitialized local variables in Analytic GJR-GARCH(1, 1) Engine

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

potentially uninitialized local variables in Analytic GJR-GARCH(1, 1) Engine

Ferdinando M. Ametrano-3
Hi all

as you probably guessed I'm doing some lint activity for 1.0 release,
so expect some more annoying message from me.

Feel free to trash all of them ;-) but if you are the author or you
have some familiarity with the code referenced please consider helping

warning C4701: potentially uninitialized local variable 'ex'
used c:\projects\quantlib\trunk\quantlib\ql\pricingengines\vanilla\analyticgjrgarchengine.cpp 268
warning C4701: potentially uninitialized local variable 'k3'
used c:\projects\quantlib\trunk\quantlib\ql\pricingengines\vanilla\analyticgjrgarchengine.cpp 279
warning C4701: potentially uninitialized local variable 'k4'
used c:\projects\quantlib\trunk\quantlib\ql\pricingengines\vanilla\analyticgjrgarchengine.cpp 279
warning C4701: potentially uninitialized local variable 'sigma'
used c:\projects\quantlib\trunk\quantlib\ql\pricingengines\vanilla\analyticgjrgarchengine.cpp 267

using potentially uninitialized local variables smells like a genuine bug to me

ciao -- Nando

RSS feed: http://www.google.com/reader/shared/ferdinando.ametrano

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: potentially uninitialized local variables in Analytic GJR-GARCH(1, 1) Engine

Luigi Ballabio
On Fri, 2009-11-27 at 12:15 +0100, Ferdinando Ametrano wrote:

> warning C4701: potentially uninitialized local variable 'ex'
> used c:\projects\quantlib\trunk\quantlib\ql\pricingengines\vanilla\analyticgjrgarchengine.cpp 268
> warning C4701: potentially uninitialized local variable 'k3'
> used c:\projects\quantlib\trunk\quantlib\ql\pricingengines\vanilla\analyticgjrgarchengine.cpp 279
> warning C4701: potentially uninitialized local variable 'k4'
> used c:\projects\quantlib\trunk\quantlib\ql\pricingengines\vanilla\analyticgjrgarchengine.cpp 279
> warning C4701: potentially uninitialized local variable 'sigma'
> used c:\projects\quantlib\trunk\quantlib\ql\pricingengines\vanilla\analyticgjrgarchengine.cpp 267
>
> using potentially uninitialized local variables smells like a genuine bug to me

Yes--in your compiler's branch detection algorithm :)

The variables above are all initialized one way or the other in a
section of code that reads:

if (init_ != true || constants_match != true || ...) {
    ... the variables are initialized to some values ...
}
else if (init_ == true && constants_match == true) {
    ... the variables are initialized to some other values ...
}

My guess is that since a final "else" is missing, the compiler doesn't
realize that between them the two conditions cover all possible cases.

Of course the if could be rewritten so that the warning disappears,
though---the "else if" could just be an "else" (and of course, the
"init_ != true" and "init_ == true" should be just "!init_" and
"init_"...)

Luigi


--

Though this be madness, yet there is method in't.
-- Hamlet, Act II, scene II



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: potentially uninitialized local variables in Analytic GJR-GARCH(1, 1) Engine

Ferdinando M. Ametrano-3
On Fri, Nov 27, 2009 at 12:30 PM, Luigi Ballabio
<[hidden email]> wrote:

>> using potentially uninitialized local variables smells like a genuine bug to me
>
> Yes--in your compiler's branch detection algorithm :)
>
> The variables above are all initialized one way or the other in a
> section of code that reads:
>
> if (init_ != true || constants_match != true || ...) {
>    ... the variables are initialized to some values ...
> }
> else if (init_ == true && constants_match == true) {
>    ... the variables are initialized to some other values ...
> }

mmm... it seems to me the condition you summarized as "..." might
really imply some other logic branch where variables are not
initialized.

Anyway I'm sure making the compiler happier would at least result in
more readable if-else code :-)

ciao -- Nando

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: potentially uninitialized local variables in Analytic GJR-GARCH(1, 1) Engine

Luigi Ballabio
On Fri, 2009-11-27 at 12:56 +0100, Ferdinando Ametrano wrote:

> On Fri, Nov 27, 2009 at 12:30 PM, Luigi Ballabio
> > The variables above are all initialized one way or the other in a
> > section of code that reads:
> >
> > if (init_ != true || constants_match != true || ...) {
> >    ... the variables are initialized to some values ...
> > }
> > else if (init_ == true && constants_match == true) {
> >    ... the variables are initialized to some other values ...
> > }
>
> mmm... it seems to me the condition you summarized as "..." might
> really imply some other logic branch where variables are not
> initialized.

No. If either init or constants_match is false, the code takes the first
branch (it's an or, so one suffices.) If not, either the conditions in
"..." are true (and the code takes the first branch) or, since init and
constant_match are both true, it takes the second branch.

Luigi


--

Things should be made as simple as possible, but no simpler.
-- Albert Einstein



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: potentially uninitialized local variables in Analytic GJR-GARCH(1, 1) Engine

Ferdinando M. Ametrano-3
On Fri, Nov 27, 2009 at 2:12 PM, Luigi Ballabio
<[hidden email]> wrote:

> On Fri, 2009-11-27 at 12:56 +0100, Ferdinando Ametrano wrote:
>> On Fri, Nov 27, 2009 at 12:30 PM, Luigi Ballabio
>> > The variables above are all initialized one way or the other in a
>> > section of code that reads:
>> >
>> > if (init_ != true || constants_match != true || ...) {
>> >    ... the variables are initialized to some values ...
>> > }
>> > else if (init_ == true && constants_match == true) {
>> >    ... the variables are initialized to some other values ...
>> > }
>>
>> mmm... it seems to me the condition you summarized as "..." might
>> really imply some other logic branch where variables are not
>> initialized.
>
> No. If either init or constants_match is false, the code takes the first
> branch (it's an or, so one suffices.) If not, either the conditions in
> "..." are true (and the code takes the first branch) or, since init and
> constant_match are both true, it takes the second branch.

ooops... now I got it.

I was confused between AND and OR... go figure :-)

so I'll commit a revisited if else: please don't forget to check my logic

ciao -- Nando

ciao -- Nando

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: potentially uninitialized local variables in Analytic GJR-GARCH(1, 1) Engine

Ferdinando M. Ametrano-3
Ok, avoided warning with cleaner if/else constructs:

http://quantlib.svn.sourceforge.net/viewvc/quantlib/branches/R01000x-branch/QuantLib/ql/pricingengines/vanilla/analyticgjrgarchengine.cpp?r1=16838&r2=16837&pathrev=16838

ciao -- Nando

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: potentially uninitialized local variables in Analytic GJR-GARCH(1, 1) Engine

Luigi Ballabio
On Fri, 2009-11-27 at 17:42 +0100, Ferdinando Ametrano wrote:
> Ok, avoided warning with cleaner if/else constructs:
>
> http://quantlib.svn.sourceforge.net/viewvc/quantlib/branches/R01000x-branch/QuantLib/ql/pricingengines/vanilla/analyticgjrgarchengine.cpp?r1=16838&r2=16837&pathrev=16838

Looks right to me.

Luigi


--

A debugged program is one for which you have not yet found the
conditions that make it fail.
-- Jerry Ogdin



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: potentially uninitialized local variables in Analytic GJR-GARCH(1, 1) Engine

Yee Man Chan
In reply to this post by Ferdinando M. Ametrano-3

Thanks for fixing my code. You guys are so efficient!

Yee Man
--- On Fri, 11/27/09, Ferdinando Ametrano <[hidden email]> wrote:

> From: Ferdinando Ametrano <[hidden email]>
> Subject: Re: [Quantlib-dev] potentially uninitialized local variables in Analytic GJR-GARCH(1, 1) Engine
> To: [hidden email]
> Cc: "QuantLib developers" <[hidden email]>
> Date: Friday, November 27, 2009, 8:42 AM
> Ok, avoided warning with cleaner
> if/else constructs:
>
> http://quantlib.svn.sourceforge.net/viewvc/quantlib/branches/R01000x-branch/QuantLib/ql/pricingengines/vanilla/analyticgjrgarchengine.cpp?r1=16838&r2=16837&pathrev=16838
>
> ciao -- Nando
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal
> Reports 2008 30-Day
> trial. Simplify your report design, integration and
> deployment - and focus on
> what you do best, core application coding. Discover what's
> new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>


     

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev