#1 2024-07-10 09:20:54

tbo
Member
Registered: 2015-04-20
Posts: 340

Function ObjArrayDelete() access violation

mORMot2, Commit 7777, Delphi 12.1, 32Bit

Access violation for these combinations in function ObjArrayDelete().

...ObjArrayHelper.Delete(aIndex: Integer): Boolean;
var
  Count: Integer;
begin
  Count := Length(Self);
  if (Count > 0)
    and (aIndex >= 0)
    and (aIndex < Count) then
  begin
    // Ok
    ObjArrayDelete(Self, aIndex);
  
    // Ok
    ObjArrayDelete(Self, Self[aIndex]);

    // raised exception class EAccessViolation with message 'Access violation at address 00FBCB6E. Read of address 70505408'.
    ObjArrayDelete(Self, Count, Self[aIndex]);

    // raised exception class EAccessViolation with message 'Access violation at address 00A2CB6E. Read of address 70505408'.
    ObjArrayDelete(Self, aIndex, False, @Count);

With best regards
Thomas

Last edited by tbo (2024-07-10 09:25:32)

Offline

#2 2024-07-10 13:33:20

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,371
Website

Re: Function ObjArrayDelete() access violation

Please try
https://github.com/synopse/mORMot2/commit/b6aeac2e

Note that

1) If you use an external "Count: integer" then you SHOULD keep this as the actual count for the whole process, otherwise it is clearly wrong and would lead to GPF.

2) All ObjArrayDelete() do check aIndex against the length() so you are not required to check it before calling it.

Offline

Board footer

Powered by FluxBB