нажмите обнаружение мусора значение - PullRequest
1 голос
/ 15 октября 2010

Я использую класс Apple TapDetectingImageView из примера Autoscroll.

Статический анализатор показывает следующее предупреждение:

Классы / TapDetectingImageView.m: 68: 30: {68: 17-68: 29}: предупреждение:

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

для прикрепленного кода ниже. Значение мусора возникает, когда переменная читается без предварительной инициализации. Но похоже, что tapCounts уже инициализирован.

Могу ли я игнорировать это, если приложение работает нормально или я должен что-то изменить?

    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];
        }
    }

Ответы [ 2 ]

0 голосов
/ 17 февраля 2016

Это связано с тем, что массив tapCounts инициализируется со значениями мусора для индексов 0 и 1.

Пожалуйста, измените строку:

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

с

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

Этоудалит предупреждение об инициализации при анализе сборки

0 голосов
/ 16 октября 2011

Это происходит, когда переменная создается, но НЕ инициализируется значением. В приведенном выше коде вы делаете это:

int tapCounts[2];
...

Но затем не инициализируйте содержимое массива, прежде чем пытаться вычислить его в операторе if несколькими строками вниз:

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

Компилятор предупреждает вас, что содержимое tapCounts [0] не инициализировано и является мусором.

...