是什么导致System.Move偶尔给出错误的结果? [英] What can cause System.Move to occasionally give wrong results?

查看:74
本文介绍了是什么导致System.Move偶尔给出错误的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几天,第三方开发的数据库组件出现了一些奇怪的问题。这些组件几个月都没有任何变化。
最近几天HAS更改的代码是我们自己的代码,我们还更新了由第三方开发的gui组件。

The last few days we have had some strange problems with our database components developed by a third party. There has been no changes to these components for months. The code that HAS changed the last few days is our own code and we have also updated our gui-components developed by another third party.

调试后,我发现在数据库组件过程之一中调用System.Move有时会产生错误的结果!

请查看下面来自数据库组件的代码,并阅读我的评论。这种不一致的行为如何发生?
谁能给我一个关于如何继续找出这种不一致行为原因的想法吗?
注意!我认为此代码没有任何问题,仅显示它是为了解释问题症状。
我的猜测是,由于我们的代码或更新的gui-component-code导致某种形式的内存损坏或某些情况。

Please take a look at the code below from the database components and read my comments. How can this inconsistent behaviour happen? Can anyone give me an idea of how to procede to find the cause of this inconsistent behaviour? NB! I dont think there is anything wrong with THIS code, it is only shown to explain the problem "symptoms". My guess is that there is some sort of memory corruption or something, caused by our code or the updated gui-component-code.

编辑:看看下面链接的博客文章。看来这可能与我的问题有关。至少在我阅读该书时,它确认System.Move可以给出错误的结果:
http://blog.excastle.com/2007/08/28/delphi-bug-of-the-day-fpu-stack-leak/

Edit: Take a look at the blogpost linked below. It seems that it could be related to my problem. At least as I read it it confirms that System.Move can give wrong results: http://blog.excastle.com/2007/08/28/delphi-bug-of-the-day-fpu-stack-leak/

编辑
对不起,我没有提前发布我的解决方案,但是来了:
使用时Delphi 2007我的问题通过使用FastMove代替System.Move得以解决。
升级到Delphi 2010后,我还没有遇到问题,我们不再使用FastMove。

Edit: Sorry for not posting my "solution" earlyer but here it comes: When using Delphi 2007 my problem was solved by using FastMove which replaces System.Move. After upgrading to Delphi 2010 i have yet to encounter the problem, an we are no longer using FastMove.

Procedure InternalDescribe;
var 
  cbufl: sb4; //sb4=LongInt
  cbuf: array[0..30] of char;
  cbufp: PChar;
  //....
begin
  //..Some code
  repeat
    //...Some code to initialize cbufp and cbufl

    //On the 15. iteration the values immediately Before Move are always these:
    //cbufp = 'STDPRODUCTSTOREDELEMENTSCOUNT'
    //cbuf = ('S', 'T', 'A', 'T', 'U', 'S', #0, 'E', 'V', 'A', 'R', 'R', 'E', 'C', 'I', 'D', #0, 'D', 'U', 'C', 'T', 'I', 'D', #0, #0, #0, #0, #0, #0, #0, #0)
    //cbufl = 29

    Move(cbufp^, cbuf, cbufl);

    //Values immediately After Move should then be:
    //cbuf = ('S', 'T', 'D', 'P', 'R', 'O', 'D', 'U', 'C', 'T', 'S', 'T', 'O', 'R', 'E', 'D', 'E', 'L', 'E', 'M', 'E', 'N', 'T', 'S', 'C', 'O', 'U', 'N', 'T', #0, #0)

    //But sometimes this Move results in this value( 1 in 5..15 times):
    //cbuf = ('S', 'T', 'D', 'P', 'R', 'O', 'D', 'U', 'C', 'T', 'S', 'T', 'O', 'R', 'E', 'D', #0, #0, #0, #0, #0, 'N', 'T', 'S', 'C', 'O', 'U', 'N', 'T', #0, #0) }

  until SomeCondition; 
  //...Some more code
end;


推荐答案

移动不会给出错误的结果,或者至少不会给出错误的结果我从未见过这种情况。您很有可能在缓冲区中遇到了意外情况。尝试在此例程中添加对Windows.OutputDebugString的调用,以查看之前和之后要复制的内容。

Move doesn't give wrong results, or at least I've never seen any situation in which it did. It's more likely that you've got something unexpected in the buffer. Try adding calls to Windows.OutputDebugString in this routine to see what you're copying before and after.

这篇关于是什么导致System.Move偶尔给出错误的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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