English 中文(简体)
tap detecting garbage value
原标题:
  • 时间:2010-10-15 05:36:57
  •  标签:
  • garbage
  • tap

I m using Apple TapDetectingImageView class from Autoscroll example.

Static analizer shows the following warning:

Classes/TapDetectingImageView.m:68:30:{68:17-68:29}: warning:

The left operand of  ==  is a garbage value
         if (tapCounts[0] == 1 && tapCounts[1] == 1) {
             ~~~~~~~~~~~~ ^

for the attached code below. Garbage value occurs when a variable is read without having been initialized first. But it seems tapCounts is initialized already.

Can I ignore it if the app is running fine or should I modify anything?

    BOOL allTouchesEnded = ([touches count] == [[event touchesForView:self] count]);

// first check for plain single/double tap, which is only possible if we haven t seen multiple touches
if (!multipleTouches) {
    UITouch *touch = [touches anyObject];
    tapLocation = [touch locationInView:self];

    if ([touch tapCount] == 1) {
        [self performSelector:@selector(handleSingleTap) withObject:nil afterDelay:DOUBLE_TAP_DELAY];
    } else if([touch tapCount] == 2) {
        [self handleDoubleTap];
    }
}   

// check for 2-finger tap if we ve seen multiple touches and haven t yet ruled out that possibility
else if (multipleTouches && twoFingerTapIsPossible) {

    // case 1: this is the end of both touches at once
    if ([touches count] == 2 && allTouchesEnded) {
        int i = 0;
        int tapCounts[2]; CGPoint tapLocations[2];
        for (UITouch *touch in touches) {
            tapCounts[i]    = [touch tapCount];
            tapLocations[i] = [touch locationInView:self];
            i++;
        }
        if (tapCounts[0] == 1 && tapCounts[1] == 1) { // it s a two-finger tap if they re both single taps
            tapLocation = midpointBetweenPoints(tapLocations[0], tapLocations[1]);
            [self handleTwoFingerTap];
        }
    }
问题回答

This occurs when a variable is created but NOT initialized to a value. In the code above you do this:

int tapCounts[2];
...

But then don t initialize the array contents to anything before attempting to evaluate it in the if statement a few lines down:

if( tapCounts[0] == 1 && tapCounts[1] == 1 ) {
   ....
}

The compiler is warning you that the contents of tapCounts[0] is not initialized and is garbage.

It s due to tapCounts array is initialized with garbage values for index 0 and 1.

Please change the line:

int tapCounts[2]; CGPoint tapLocations[2];

with

int tapCounts[2] = {0,0}; CGPoint tapLocations[2] = {0,0};

This will remove the initialize warning while analyzing build





相关问题
tap detecting garbage value

I m using Apple TapDetectingImageView class from Autoscroll example. Static analizer shows the following warning: Classes/TapDetectingImageView.m:68:30:{68:17-68:29}: warning: The left operand of ...

Double Tap for certain part of view

I am bit stacked with a functionality that should perform a certain task after double taping on a certain place on UIView. I know how to count number of taps, but do not know how to determinate which ...

jQtouch tap and link problem

I m having a problem with jQtouch when using tap on links, I m trying to get a link to change background color when tapped a la iphone appstore (the blue color) so I m using this code : <script&...

Making images appear... How?

Could someone please tell me how to make an image appear when the user taps the screen and make it appear at the position of the tap. Thanks in advance, Tate

iPhone + detect tap of disabled UIControl

I am developing In App purchase for one existing application. Scenario is something like I have a feature in application (which contain UITextField control), which is initially disabled and when user ...

OpenVPN TAP Driver Installation

I m trying to control multiple instances of OpenVPN s TAP driver in windows via tapinstall. It seems that because all of the devices have the same HWID -- tap0901 -- I m unable to remove any single ...

热门标签