请帮我看下这段代码的问题?

jinggangshi 2011-07-04 10:13:23

char* buf = (char*)LocalAlloc(LPTR, 8);
//::ZeroMemory(buf, 8);
/*
遍历字符串进行转码
*/
while( *pWork != 0x0 )
{
::ZeroMemory(buf, 8);
if ( *pWork != '!' && *pWork != '@' && *pWork != '#' &&
*pWork != '$' && *pWork != '&' && *pWork != '*' &&
*pWork != '(' && *pWork != ')' && *pWork != '=' &&
*pWork != ':' && *pWork != '/' && *pWork != ';' &&
*pWork != '?' && *pWork != '+' && *pWork != '\'' &&
*pWork != '.' )
{
sprintf_s(buf, d_size, "%%%2x", *pWork);
//strcat_s(des, d_size, buf);
}
else
{
sprintf_s(buf, d_size,"%c", *pWork);
}
strcat_s(des, d_size, buf);

pWork++;
}
LocalFree(buf);//问题出在这里


纯 MSIL 公共语言运行库支持(/clr:pure)--。使用这个选项能运行,但有时出现托管错误
公共语言运行库支持(/clr)--使用这个选项能运行,但有LocalFree(buf)会中断,EAP[RSAEnCrypt.exe]: Heap block at 001BA9D8 modified at 001BA9E8 past requested size of 8
Windows 已在 RSAEnCrypt.exe 中触发一个断点。

其原因可能是堆被损坏,这也说明 RSAEnCrypt.exe 中或它所加载的任何 DLL 中有 bug。

其他选项编译不能通过。

为什么会在LocalFree(buf)这出问题,麻烦名位指点迷津,先行谢过!
...全文
77 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yage_18 2011-08-04
  • 打赏
  • 举报
回复
我不用带_s的函数,哈哈
这个只能在Windows平台下用
感觉也不好用
绿绿的阳光 2011-07-20
  • 打赏
  • 举报
回复
#ifdef __AIRFLUX_LOG_FILE_H__
#define __AIRFLUX_LOG_FILE_H__

#include "Common_UserType.h"
#include <stdio.h>

class CAirFluxLogFile
{
public:
CAirFluxLogFile(const string &strFilePath, const string &strFileName);
~CAirFluxLogFile();
void WriteLog(const string &strLogMsg);

private:
void CreateNewLogFile();
void CloseLogFile();
void DoWriteLog(const string &strLogMsg);

//打印开头与结尾
void PrintHeader();
void PrintFooter();

private:
//输出日志文件名
string m_strFilePath;
string m_strFileName;

//日志文件句柄
FILE *m_file;

//日志条数
UINT32 m_ulRecordCnt;
};
#endif
jinggangshi 2011-07-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 isjoe 的回复:]
没看到托管代码。。。。。。。你不需要添加托管编译选项
[/Quote]

你说的有理,我有很多在非托管中编写的类,在托管中引用Dll就出错。
但为什么用sprintf就没有问题?能否赐教
Zj_Torres 2011-07-15
  • 打赏
  • 举报
回复
表示没见过sprintf_s这个东西
isjoe 2011-07-15
  • 打赏
  • 举报
回复
没看到托管代码。。。。。。。你不需要添加托管编译选项
jinggangshi 2011-07-05
  • 打赏
  • 举报
回复
sprintf_s(buf, d_size, "%%%2x", *pWork);

我将sprintf_s改成sprintf,LocalFree(buf)就能正常运行了,为什么啊?
phyf_Anlymi 2011-07-04
  • 打赏
  • 举报
回复
关注!~

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧