Logic Error: The left operand of '&' is a garbage value
-
16-04-2021 - |
Question
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'
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:
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
Thanks any suggestion!
Solution
sidestep it by initializing inbuf to an empty char array:
unsigned char inbuf[4] = {};
unsigned char outbuf[3];
OTHER TIPS
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.
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".