[fpc-pascal] access violation?

Sven Barth pascaldragon at googlemail.com
Sat Jul 28 10:03:26 CEST 2018


Am 27.07.2018 um 19:41 schrieb Ryan Joseph:
>
>> On Jul 27, 2018, at 11:24 AM, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
>>
>> You can't if you compile with -CR.
>> The RTL is not compiled with objectchecks, so it works there.
>>
>>> According to this test not only can you call methods on nil objects but
>>> it calls the method statically (like a class method), i.e the test
>>> prints “DoThis”. How is that possible?
>> Self on x86_64 target is just a hidden argument.
>> It won't work with virtual methods.
> This is all news to me. I had no idea I was possibly compiling programs where I could call nil objects.
Normal, non-virtual methods are essentially ordinary 
functions/procedures. In contrast to static functions/procedures they 
have a hidden parameter that contains the value of Self. As Self is 
merely a pointer there is no problem if Self should be Nil as long as it 
isn't dereferenced (which happens if you access a field or a call a 
virtual method).
Calling a virtual method would fail immediately.
> How do I disable this? I just ran this test program with -CR and I still calls the method statically.
The method is always called statically, -CR doesn't change anything 
there. Calling a virtual method however would fail with EObjectCheck 
instead of EAccessViolation.
The method you provided below would not fail anyway, because it doesn't 
dereference Self. If you'd however access for example a field of your 
class then a check should be inserted inside the method. For some reason 
it isn't however and *that* is the bug.

Regards,
Sven



More information about the fpc-pascal mailing list