Skip to content

Instantly share code, notes, and snippets.

@Gernot
Created September 9, 2011 14:35
Show Gist options
  • Save Gernot/1206389 to your computer and use it in GitHub Desktop.
Save Gernot/1206389 to your computer and use it in GitHub Desktop.
ARC + Analyzer
+ (NSString *)nx_stringWithUUID;
{
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef string = CFUUIDCreateString(kCFAllocatorDefault, theUUID);
CFRelease(theUUID);
NSString *returnValue = (__bridge_transfer NSString*)string;
return returnValue;
/*
At this point I get the following Analyzer result:
/Users/gernot/Code/[...]/NSString+NXKit.m:25:5:{25:12-25:23}{21:5-21:59}: warning: Address of stack memory associated with local variable 'string' returned to caller
return returnValue;
^ ~~~~~~~~~~~
*/
}
@Gernot
Copy link
Author

Gernot commented Sep 9, 2011

Ok, this seems like an Analyzer Bug. Here's a fix for line 7:

    NSString *returnValue = [NSString stringWithString:(__bridge_transfer NSString*)string];

Thanks to @MrToto for the suggestion, I owe you a beer. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment