#1 2023-05-10 23:53:58

blue
Member
Registered: 2023-05-05
Posts: 9

TMemoryMapText.LoadFromMap issue

mormot.core.buffers.pas

procedure TMemoryMapText.LoadFromMap(AverageLineLength: integer = 32);
var
  P: PUtf8Char;
begin
  fLinesMax := fMap.FileSize div AverageLineLength + 8;
  GetMem(fLines, fLinesMax * SizeOf(pointer));
  P := pointer(fMap.Buffer);
  fMapEnd := P + fMap.Size;
  // except when loading a empty file. (P = nil)
  if (PWord(P)^ = $BBEF) and
     (P[2] = #$BF) then
    inc(P, 3); // ignore UTF-8 BOM
  ParseLines(P, fMapEnd, self);
  if fLinesMax > fCount + 16384 then
    Reallocmem(fLines, fCount * SizeOf(pointer)); // size down only if worth it
end;

Offline

#2 2023-05-11 06:59:27

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

Re: TMemoryMapText.LoadFromMap issue

How do you initialize TMemoryMapText ?

LoadFromMap should not be called if the file was empty.

Anyway, please try https://github.com/synopse/mORMot2/commit/6af3d452

Offline

#3 2023-05-11 07:55:17

blue
Member
Registered: 2023-05-05
Posts: 9

Re: TMemoryMapText.LoadFromMap issue

For example:

var
  mmt: TMemoryMapText;
begin
  if not FileExists(fileName) then
    Exit;
  mmt := TMemoryMapText.Create(fileName);  // exception
  ...
end;

Offline

Board footer

Powered by FluxBB