3

我的 C 知识在这里可能存在一个漏洞,但我对为什么会发生这种情况有点困惑。

(lldb) p lineGroup
(NSInteger) $17 = -1
(lldb) p (lineGroup > 4)
(bool) $18 = true
(lldb) p (lineGroup < 0 )
(bool) $19 = false
(lldb) p (-1 < 0)
(bool) $20 = true
(lldb) p ((int)lineGroup < 0 )
(bool) $21 = false
(lldb) p ((int)lineGroup > 4)
(bool) $22 = true
(lldb) 

lineGroup变量分配如下:

- (void)gotLineGroupInformation:(NSString *)lineGroupString
{
    NSInteger lineGroup = [lineGroupString integerValue];
    if(lineGroup >= 0)
    {
        // Always gets called
    }
    else
    {
        // Never gets called
    }
}

谢谢,安迪

4

1 回答 1

2

lldb 问题似乎与Objective C 整数比较错误中的完全相同:

卡尔诺鲁姆在回应中说:

已确认 - 这是 lldb IR 解释器中的一个错误。

这是修复它的补丁的链接:http: //lists.cs.uiuc.edu/pipermail/lldb-commits/Week-of-Mon-20130520/008569.html


关于您的代码,我尝试通过此测试重现该错误但没有成功:

NSString *lineGroupString = @"-1";
NSInteger lineGroup = [lineGroupString integerValue];
if(lineGroup >= 0)
{
    NSLog(@"positive");
}
else
{
    NSLog(@"negative"); // This log is correctly called every time
}

也许您应该尝试NSLog对此进行调试(特别是lineGroupString输入函数后的值是什么?)。

于 2013-07-22T10:21:18.453 回答