• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CLang wrong analysis?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CLang wrong analysis?


  • Subject: Re: CLang wrong analysis?
  • From: Bavarious <email@hidden>
  • Date: Mon, 28 Mar 2011 17:05:47 -0300

On 28/03/2011, at 11:36, Jean-Denis Muys wrote:

>> From XCode 4.01 analyze, this line:
>
>        for (j = i; j < (i + 3); j++) {
>
> reports: "The left operand to '+' is always 0".
>
> I am scratching my head as I don't think that is correct. Here is the full routine:
>
>
> + (NSString*)base64forData:(NSData*)theData {
>
>
> const uint8_t* input = (const uint8_t*)[theData bytes];
> NSInteger length = [theData length];
>
>
>    static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
>
>
>    NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
>    uint8_t* output = (uint8_t*)data.mutableBytes;
>
>
> NSInteger i;
>    for (i=0; i < length; i += 3) {
>        NSInteger value = 0;
> NSInteger j;
>        for (j = i; j < (i + 3); j++) { // <------------- The left operand to '+' is always 0
>            value <<= 8;
>
>
>            if (j < length) {
>                value |= (0xFF & input[j]);
>            }
>        }
>
>
>        NSInteger theIndex = (i / 3) * 4;
>        output[theIndex + 0] =                    table[(value >> 18) & 0x3F];
>        output[theIndex + 1] =                    table[(value >> 12) & 0x3F];
>        output[theIndex + 2] = (i + 1) < length ? table[(value >> 6)  & 0x3F] : '=';
>        output[theIndex + 3] = (i + 2) < length ? table[(value >> 0)  & 0x3F] : '=';
>    }
>
>
>    return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
> }
>
>
> Am I missing something?
>
> Jean-Denis

This is a CSA bug that has already been reported and fixed by the LLVM team:

http://llvm.org/bugs/show_bug.cgi?id=9541

As described in the bug report, you can define the variable inside the for expression as a workaround for this static analyser bug, or you could wait until Apple release another version of Xcode+Clang including the fix.

-- Bavarious _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: CLang wrong analysis?
      • From: Sean McBride <email@hidden>
References: 
 >CLang wrong analysis? (From: Jean-Denis Muys <email@hidden>)

  • Prev by Date: CoreData Versioning in XCode4
  • Next by Date: Re: How to get warnings for missing methods in older SDKs
  • Previous by thread: Re: CLang wrong analysis?
  • Next by thread: Re: CLang wrong analysis?
  • Index(es):
    • Date
    • Thread