On 12 Dec 2013, at 11:52, 2551 <2551p...@gmail.com> wrote:

> Hi folks
> 
> I need some help with a logic error the Static Analyzer is throwing up. I 
> didn’t write this code (in fact, its a piece of Apple sample code I’m resuing 
> in my project), and I’m not quite sure how to correct it. It goes like this, 
> where the numbers [1], [2], [3], [4] represent the end points of the 
> analyzer's blue arrows:
> 
>   [1] const NSRect bounds = [self bounds];
> 
>    [backgroundColor set];
>    NSRectFill(dirtyRect);
> 
>    const NSRulerOrientation orientation = [self orientation];
>    NSRect borderLineRect;
>    [2] switch (orientation) {
>        case NSVerticalRuler:
>            borderLineRect = NSMakeRect(NSMaxX(bounds)-1.0, 0, 1.0, 
> NSHeight(bounds));
>            break;
>        case NSHorizontalRuler:
>            borderLineRect = NSMakeRect(0, 0, NSWidth(bounds), 1.0);
>            break;
>    }

If orientation happens to have a value *other* than NSVerticalRuler or 
NSHorizontalRuler, you’ll reach this point with borderLineRect containing 
garbage since it’s never been filled in properly. This is what the analyser is 
complaining of I believe.
> 
> 
>    [3]if [4]([self needsToDrawRect:borderLineRect]) {
>        [[backgroundColor shadowWithLevel:0.4] set];
>        NSRectFill(borderLineRect);
> 
> The error message says, in full: Passed-by-value struct argument contains 
> uninitialized data (e.g., via the field chain: 'origin.x’). 
> 
> 
> Thoughts much appreciated.
> 
> 
> Phil
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/mabdullah%40karelia.com
> 
> This email sent to mabdul...@karelia.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to