[LLVMbugs] [Bug 7766] New: Maybe spurious warnings about multiplying by one

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jul 30 14:33:05 PDT 2010


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

           Summary: Maybe spurious warnings about multiplying by one
           Product: clang
           Version: trunk
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: tjw at omnigroup.com
                CC: llvmbugs at cs.uiuc.edu


In checker-246, we get a warning about multiplying by one in the following
code. In this case, and several others where the +=0 and *=1 warnings pop up,
it is of the pattern were we are setting up a name for a constant and then
spelling out a more explicit formula (basically showing our work).

I've yet to see these idempotence catch a bug, so I'm not sure what sort of
things these would save me from (might be worth these false positives, might
not). Anyway, I thought I'd mention this problem though I'm not sure you
can/should fix it =)

CGImageRef OQCreateVerticalGradientImage(CGGradientRef gradient, CFStringRef
colorSpaceName, size_t height, BOOL flip)
{
    size_t width = 1; // One pixel wide
    size_t bytesPerRow = 4*width; <<--- warning here

    CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(colorSpaceName);
    CGContextRef ctx = CGBitmapContextCreate(NULL, width, height,
8/*bitsPerComponent*/, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedFirst);
    CFRelease(colorSpace);

    CGRect bounds = CGRectMake(0, 0, width, height);
    CGContextAddRect(ctx, bounds);
    CGContextClip(ctx);

    CGPoint startPoint = bounds.origin;
    CGPoint endPoint = (CGPoint){ CGRectGetMinX(bounds), CGRectGetMaxY(bounds)
};

    if (flip)
        SWAP(startPoint, endPoint);

    CGContextDrawLinearGradient(ctx, gradient, startPoint, endPoint,
0/*options*/);

    CGContextFlush(ctx);
    CGImageRef gradientImage = CGBitmapContextCreateImage(ctx);
    CFRelease(ctx);

    return gradientImage;
}

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list