警告C4789:内存复制的目标太小 [英] warning C4789: destination of memory copy is too small

查看:427
本文介绍了警告C4789:内存复制的目标太小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个C代码,我们之前使用较旧版本的VC ++编译,它运行良好。在升级过程中,我们使用Visual 2008 Express Edition来编译代码。代码编译良好并创建输出dll,但在运行时它显示内存异常。我们回到日志文件并检查警告消息。其中一条警告信息显示警告C4789:内存复制的目的地太小。导致此警告消息的代码如下: -



Hi,

I am having a C code which we compiled earlier using older version of VC++ and it worked fine. During our upgrade we are using Visual 2008 Express Edition to compile our code.The code is compiling well and creating an output dll, but during run time it is showing memory exception. We went back to log file and checked for warning messages. One of the warning message says warning C4789: destination of memory copy is too small. The Code which caused this warning message is as follows:-

memcpy(szOutputNum,
       pRPS->GroupName1,
       sizeof(pRPS->GroupName1)-1);





我们已经注释掉了这部分代码并再次创建了dll。这次我们运行应用程序时工作正常。但是我们在这段代码中有一个逻辑来创建一个我们需要的报告。



所以,你们中的任何人都可以帮助我解决这个问题。 />


谢谢,

S1



We have commented out this portion of code and created the dll again. This time when we run the application it is working fine. But we had an logic in this code to create a report which is required for us.

So, Can any one of you help me in resolving this issue.

Thanks,
S1

推荐答案

错误信息非常明确:内存复制的目的地太小

这意味着你试图将一个大字符串复制到一个较小的区域,这可能会导致严重的问题。 />
我想到两种可能性:

1)你得到的参数顺序错误:第一个参数是目的地,第二个是来源。

2)数组szOutputname被声明为具有不足的空间来保存当前在结构中的字符串。



使用调试器,并查看变量 - 它应该是公平的很明显你犯了哪些错误。
The error message is pretty explicit: "destination of memory copy is too small"
What it means is that you are trying to copy a large string into a smaller area, and it may cause serious problems.
Two possibilities spring to mind:
1) You got the order of parameters wrong: the first parameter is the destination, the second is the source.
2) The array szOutputname was declared with insufficent space to hold the string currently in the structure.

Use the debugger, and look at the variables - it should be fairly obvious which error you have made.


这篇关于警告C4789:内存复制的目标太小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆