2011-10-08 25 views
0

我刚刚更新到狮子,现在我的应用程序崩溃,在旧版本中工作正常。它在没有日志的memset函数上崩溃。得到崩溃om内存集更新到狮子和xCode

unsigned char *theValue; 
add(theValue, someotherValues); 

我已经过了theValue参考作用

add(unsigned char *inValue, some other perameter) { 
memset(inValue,0,sizeOf(inValue)); // **here it is crashing** 
} 
+0

什么'theValue'点?而且,即使它指向某种合理的东西,代码也没有意义;你试图设置指针'theValue'指向的字符,但是使用指针本身的大小来确定要设置多少内存。 –

+0

我编辑过的问题。 – iOSPawan

回答

2

在声明theValue和致电add()之间是否真的没有代码?如果是这样,那就是你的问题。您将传递一个随机值作为memset()的第一个参数。

对于这个代码是有道理的,你要分配的内存块theValue并通过其规模add(),像这样:

unsigned char *theValue = new unsigned char[BUFSIZE]; // Or malloc 
add(theValue, BUFSIZE, ...); 

void add(unsigned char *inValue, size_t bufsize, ...) { 
    memset(inValue, 0, bufsize); 
    ... 
} 
+0

谢谢@马塞洛,你救了我的一天。 – iOSPawan

1

你的inValue分配内存?

1)

add(unsigned char *inValue, some other perameter) { 
    inValue = (unsigned char*)malloc(sizeof(inValue)); 
    memset(inValue,0,sizeOf(inValue)); // **here it is crashing** 
} 

2)

theValue = (unsigned char*)malloc(sizeof(inValue)); 
add(theValue, ...) 
1
unsigned char *theValue; 

这指向的存储器(随机比特或0)。在您拨打malloc之前,您并不拥有它所指向的内容,因此您无法真正记忆它。

+0

这是错过了'sizeof()'全部滥用的观点。 –

+0

刚从我看到的第一个问题开始;我想我们会处理任何其他人,因为他遇到他们:) – deanWombourne