Recently I've ported a huge chunk of code form C++ to Delphi.

Recently I've ported a huge chunk of code form C++ to Delphi. The code is full with pointers. Despite project compiling and kind of working, I'm seeing some weird results from time to time, which leads me to think there might be bugs with pointer handling - I've already found a few. The problem is that they are really hard to track down.

Maybe you have some tips, for such cases:

  var a: PSingle;
  GetMem(a, SizeOf(Single));
  a^ := 1.1;
  someFunc(@a);// <<-- Bug here. someFunc needs PSingle, but get a PPSingle instead

In the example, there's erroneous @ used. Worst of all program does not crash, just deals with that erroneous data and keeps running.

How do you track down pointer bugs like these?

Comments