开发者

memset on a statically-allocated zlib Byte array in a library crashes an Objective-C++ program

开发者 https://www.devze.com 2023-03-22 14:55 出处:网络
I\'m writing a library that uses a statically-allocated C-array of type Byte, defined in zlib.h.I\'m finding that the code crashes on a call to memset.The complete code looks like this:

I'm writing a library that uses a statically-allocated C-array of type Byte, defined in zlib.h. I'm finding that the code crashes on a call to memset. The complete code looks like this:

Byte compressedDataBuffer[kLabelBufSiz]; 
memset (compressedDataBuffer, 0, (kLabelBufSiz * sizeof(Byte)));

I tried pre-computing the value of kLabelBufSiz * sizeof(Byte) and using the numeric value for the memset, but it made no difference. This is a single-threaded program and there is no code between the two calls, so I know that the memory and pointer are not changing. I confirmed that sizeof(Byte) is 1. I tried changing the array type to char, and that stopped the crash, so it seems that the Byte type may be playing a role here.

I wrote a smalle开发者_JAVA技巧r program that calls this library function, and that one does not crash. The non-crashing program is pure C++, whereas the crashing one is Objective-C++. I'm building them both on Mac OSX 10.6.7, with gcc-4.2 and XCode. Is there something about ObjC++ that could cause problems here? I've never had problems with C++ libraries called from ObjC++ before, but that doesn't mean they don't exist. Any help is greatly appreciated!


Byte is a wrapper class. use char instead of byte. unless you have to use Byte, in that case, don't use memset

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号