[fpc-devel] 019605: Safety check for "const s: string" (similar to Range or Overflow checks)

Florian Klämpfl florian at freepascal.org
Thu Jun 23 23:13:11 CEST 2011


Am 23.06.2011 23:03, schrieb Martin:
> And what exactly does checkpointer check?

Check if the pointer points into a allocated memory block.

Combined with heaptrc.keep_released:=true, this is a very powerful check
and even more if heaptrc is compiled with FPC_HEAPTRC_EXTRA. Downside is
a slight slow down and a heavily increased memory consumption because
keep_released:=true forces the heap manager never to reused a used
memory block so checkpointer finds any dangling pointer. But I think it
finds almost all pointer related problems.

With the default settings (keep_released:=false) it gets not all of them
because a memory block might be already reallocated and the pointer
might look valid.

I propose this because my standard procedure if something strange
happens and I suspect heap corruption and pointer problemes:
- compile with -gh
- use keep_released:=true
- use a heaptrc unit compiled with FPC_HEAPTRC_EXTRA

> 
> That s is not nil ? => s will never be nil. If something goes wrong, s
> points to memory of which nothing is known (could be unallocated, could
> be allocated by something else)

Not with heaptrc.keep_released:=true

> 
> On 23/06/2011 21:37, Florian Klämpfl wrote:
>> Am 23.06.2011 22:36, schrieb Martin:
>>>> procedure Foo(const s: string);
>>>>     begin
>>>>       proc;
>>> I assume the below is supposed to be the hidden / automatic check?
>> Yes.
>>
>>> (since the above was the unwarranted change to s)
>>>
>>> But what does it test (besides from being an assignment?
>> This is only to demonstrate that checkpointer detects the error.
>> _______________________________________________
>> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
>> http://lists.freepascal.org/mailman/listinfo/fpc-devel
> 
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
> 




More information about the fpc-devel mailing list