Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passed-by-value struct argument contains uninitialized data

I am getting the following "Passed-by-value struct argument contains uninitialized data" in the code section below:

for ( int i = 0; i < 48; i++ )
{

    CGPoint posLevel;
    LevelButton* pBtn;
    if ( i >= 0 && i < 24 )
    {
        int nXX = (i % 4 + 1);

        if ( i < [pBtnArray count] )
        {
            posLevel = ccp( (spMask.position.x - mySize.width / 2) + mySize.width / 5 * nXX, 
                           mySize.height - mySize.height / 7 * (i / 4 + 1));
            pBtn = [pBtnArray objectAtIndex:i];
            if ( pBtn != nil )
            {
                [pBtn move:posLevel];
            }

        }

    }

With the arrows added by xcode, if these help??

enter image description here

Once the commented out code is removed, there is not much code here, so I dont understand what the issue is that XCode is throwing up.

Any help in removing this error would be appreciated!

like image 715
R2D2 Avatar asked Jan 25 '26 01:01

R2D2


1 Answers

The code in your screenshot is of the form

CGRect posLevel;
if (mySize.height < 568) {
    posLevel = ...;
}
if (mySize.height >= 568) {
    posLevel = ...;
}
[pBtn move:posLevel];

and it seems that the static analyzer does not recognize that either the first or the second if-block is executed in any case. The blue arrows indicate a flow where both if-blocks are not executed, and in that case posLevel would be undefined.

You can fix that by using if-else:

CGRect posLevel;
if (mySize.height < 568) {
    posLevel = ...;
} else {
    posLevel = ...;
}
[pBtn move:posLevel];
like image 152
Martin R Avatar answered Jan 27 '26 18:01

Martin R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!