debug可以,release不行,release里加了一句无关的代码又可以了
通过打印日志文件,发现有个值本该是那样结果是0,debug是对的。
但在之前在打印一串无用的日志,结果release版本又对了,不晓得是怎么回事
代码其实没啥特别的,给上便于说明
- C/C++ code
LogDll("1111"); // LogDll("compressSize",pHeader->compressSize); // LogDll("uncompressSize",pHeader->uncompressSize); unsigned char* src=new unsigned char[pHeader->compressSize]; unsigned char* dst=new unsigned char[pHeader->uncompressSize]; fread(src,1,pHeader->compressSize,fr); unsigned long dstLen; uncompressRaw(dst,&dstLen,src,pHeader->compressSize); LogDll("dstLen",dstLen); fwrite(dst,1,pHeader->uncompressSize,fw);
在debug版本下LogDll("dstLen",dstLen);打印出来的是对的,但release下却是0,加上一句LogDll("1111");却又对了,以前也没出现这种情况的
是内存泄露的问题吗?
[解决办法]
一般这么定义比较放心:
unsigned char* src=new unsigned char[pHeader->compressSize+1];
src[pHeader->compressSize] = 0;
[解决办法]
函数里面有没有什么0与非0的判断,debug初始为0xcc,release初始为随机值,也可能是0,万一正好背时.