Logic Error: The left operand of '&' is a garbage value
Asked Answered
C

3

11

I used Twitter-OAuth-iPhone to synchronize the message in my app. It's all right in iOS4.
After upgraded to iOS5, choose menu 'Product' > 'Analyze', and got a few warnings.

In NSData+Base64.m, It's warning 'The left operand of '&' is a garbage value' enter image description here

Codes here:

if( ixinbuf == 4 ) {
ixinbuf = 0;
outbuf [0] = ( inbuf[0] << 2 ) | ( ( inbuf[1] & 0x30) >> 4 );
outbuf [1] = ( ( inbuf[1] & 0x0F ) << 4 ) | ( ( inbuf[2] & 0x3C ) >> 2 );
outbuf [2] = ( ( inbuf[2] & 0x03 ) << 6 ) | ( inbuf[3] & 0x3F );

for( i = 0; i < ctcharsinbuf; i++ ) 
    [mutableData appendBytes:&outbuf[i] length:1];
}

And there are other error message: error

Sorry I am a novice and have no any clue about these problems.
Would you help me fix it please?
Many THANKS!

Edit------------
Logic loop screenshot:

removing dead ImageShack link

Full Codes: https://github.com/bengottlieb/Twitter-OAuth-iPhone/blob/master/Twitter+OAuth/MGTwitterEngine/NSData+Base64.m

Thanks any suggestion!

Combined answered 20/10, 2011 at 15:29 Comment(1)
Click on the message and it will show you where the garbage value comes from. (Post a screenshot if you still need help.)Lubbi
B
22

sidestep it by initializing inbuf to an empty char array:

unsigned char inbuf[4] = {};
unsigned char outbuf[3];
Beekman answered 15/11, 2011 at 17:29 Comment(0)
N
2

Oh, very nice.

What Clang is telling you here is that, under some very specific circumstances, you may end up never initializing inbuf[1]. I believe this might happen for input which looked something like:

a=

There's another major issue being pointed out here -- the sizes of inbuf and outbuf are swapped. Should be char inbuf[4], outbuf[3], not vice versa.

Normative answered 21/10, 2011 at 0:24 Comment(1)
Thank you @duskwuff. I've changed line 35 from 'unsigned char inbuf[3], outbuf[4];' to 'unsigned char inbuf[4], outbuf[3];'.The yellow warning disappeared(great!). But the logic errors is still displayed. Any more hints?Combined
C
0

You can add a if statement to ensure that the inbuf[x] has some value in it

if (sizeof(inbuf[1]) > 0x1)
    outbuf [0] = ( inbuf[0] > 4 );
if (sizeof(inbuf[2]) > 0x1)
    outbuf [1] = ( ( inbuf[1] & 0x0F ) > 2 );
if (sizeof(inbuf[3]) > 0x1)
    outbuf [2] = ( ( inbuf[2] & 0x03 ) 

I'm not sure though if it's "fool proof".

Contemporary answered 26/10, 2011 at 4:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.