我正在使用Autoscroll示例中的Apple TapDetectingImageView类。
静态分析器显示以下警告:
类别/ 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];
}
}
答案 0 :(得分:0)
当创建变量但未初始化为值时会发生这种情况。在上面的代码中,您可以这样做:
int tapCounts[2];
...
但是在尝试在if语句中对它进行评估几行之前,不要将数组内容初始化为任何内容:
if( tapCounts[0] == 1 && tapCounts[1] == 1 ) {
....
}
编译器警告您tapCounts [0]的内容未初始化并且是垃圾。
答案 1 :(得分:0)
这是由于tapCounts数组初始化为索引0和1的垃圾值。
请更改行:
int tapCounts[2]; CGPoint tapLocations[2];
与
int tapCounts[2] = {0,0}; CGPoint tapLocations[2] = {0,0};
这将在分析构建
时删除初始化警告