Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c &引用;尝试创建一个临时id缓冲区,该缓冲区太大或计数为负数;NSArray上的NSGenericException?_Objective C_Exception_Crash_Nsarray - Fatal编程技术网

Objective c &引用;尝试创建一个临时id缓冲区,该缓冲区太大或计数为负数;NSArray上的NSGenericException?

Objective c &引用;尝试创建一个临时id缓冲区,该缓冲区太大或计数为负数;NSArray上的NSGenericException?,objective-c,exception,crash,nsarray,Objective C,Exception,Crash,Nsarray,我有以下几行代码(a1&a2属于NS{Mutable,}数组类型): 根据Critercism,第二行崩溃时出现NSGenericException和消息: *** attempt to create a temporary id buffer which is too large or with a negative count (18446744073709551556) -- possibly data is corrupt 堆栈跟踪的底部如下所示: 0 CoreFoundation

我有以下几行代码(
a1
&
a2
属于NS{Mutable,}数组类型):

根据Critercism,第二行崩溃时出现
NSGenericException
和消息:

*** attempt to create a temporary id buffer which is too large or with a negative count (18446744073709551556) -- possibly data is corrupt
堆栈跟踪的底部如下所示:

0   CoreFoundation 0x000000018595e084 __exceptionPreprocess + 132
1   libobjc.A.dylib 0x0000000195f940e4 objc_exception_throw + 56
2   CoreFoundation 0x000000018586830c -[NSArray objectsAtIndexes:] + 1124
3   .... line of code for `[a2 addObjectsFromArray:[items objectsAtIndexes:is]]` ...
是什么导致了这次坠机

如果尝试创建位置或长度为
(NSUInteger)-60
(可能是异常中的数字)的索引集,
-initWithIndexesInRange:
已失败(出现另一个异常)。我尝试过的其他“不正确”范围也被捕获

如果我尝试只输入
-objectsAtIndexes:
一个无效指针(例如再次输入-60),则应用程序会因
EXC\u BAD\u访问崩溃而崩溃,而不是我看到的异常


尝试使用Google查找此错误只显示1次命中-(第564行)。。。但较新版本的CoreFramework不再包含该消息(可能只是被移动到了其他地方)。

在编写一个小程序来迭代可能的位置+长度组合后,结果表明,只要
length=1-location
,就会发生此崩溃

例如:

NSRange     range = NSMakeRange(50, (NSUInteger)-49);
NSIndexSet *is    = [[NSIndexSet alloc] initWithIndexesInRange:range];
NSLog(@"indexSet: %@", is);
(void)[@[@1,@2,@3] objectsAtIndexes:is];
产出:

crash[19549:507] indexSet: <NSIndexSet: 0x7fe698402de0>[number of indexes: 18446744073709551567 (in 1 ranges), indexes: (50-0)]
crash[19549:507] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** attempt to create a temporary id buffer which is too large or with a negative count (18446744073709551567) -- possibly data is corrupt'
*** First throw call stack:
    [...]
crash[19549:507]索引集:[索引数:18446744073709551567(在1个范围内),索引:(50-0)]
崩溃[19549:507]***由于未捕获的异常“NSGenericeException”而终止应用程序,原因:“***尝试创建一个临时id缓冲区,该缓冲区太大或计数为负数(18446744073709551567)——数据可能已损坏”
***第一次抛出调用堆栈:
[...]

那么什么是
a.count
呢?那应该是
a1
。。。现在修好了。感谢您的注意。如果没有更多信息,很难看到逻辑,但是您使用的是
a1
中的大小,但将其应用于
a2
。我最感兴趣的是如何使
-ObjectsIndex:
以崩溃报告的方式崩溃。。。我可以让它崩溃,但没有那个特殊的例外。我认为计算位置和长度参数背后的逻辑并不重要。
crash[19549:507] indexSet: <NSIndexSet: 0x7fe698402de0>[number of indexes: 18446744073709551567 (in 1 ranges), indexes: (50-0)]
crash[19549:507] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** attempt to create a temporary id buffer which is too large or with a negative count (18446744073709551567) -- possibly data is corrupt'
*** First throw call stack:
    [...]