From 30c06d66c3c30adfee4d061a0902dc79924cd7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Van=20Canneyt?= Date: Tue, 18 Mar 2025 16:00:40 +0100 Subject: [PATCH] * Dyn array for FSecTbl and FSymTbl --- compiler/ogcoff.pas | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/compiler/ogcoff.pas b/compiler/ogcoff.pas index 2ae46f93b3..1ff60bcc22 100644 --- a/compiler/ogcoff.pas +++ b/compiler/ogcoff.pas @@ -40,6 +40,9 @@ interface PE_DATADIR_ENTRIES = 16; type + + TObjSymbolArray = array of TObjSymbol; + TObjSectionArray = array of TObjSection; tcoffpedatadir = packed record vaddr : longword; size : longword; @@ -178,10 +181,10 @@ interface FCoffStrs : TAnsiCharDynArray; FCoffStrSize: longword; { Convert symidx -> TObjSymbol } - FSymTbl : ^TObjSymbolArray; + FSymTbl : TObjSymbolArray; { Convert secidx -> TObjSection } FSecCount : Longint; - FSecTbl : ^TObjSectionArray; + FSecTbl : TObjSectionArray; win32 : boolean; bigobj : boolean; function GetSection(secidx:longint):TObjSection; @@ -252,9 +255,6 @@ interface procedure MemPos_ExeSection(const aname:string);override; end; - TObjSymbolArray = array[0..high(word)] of TObjSymbol; - TObjSectionArray = array[0..high(smallint)] of TObjSection; - TDJCoffAssembler = class(tinternalassembler) constructor create(info: pasminfo; smart:boolean);override; end; @@ -2271,10 +2271,8 @@ const pemagic : array[0..3] of byte = ( begin FCoffSyms.free; FCoffStrs:=nil; - if assigned(FSymTbl) then - freemem(FSymTbl); - if assigned(FSecTbl) then - freemem(FSecTbl); + FSymTbl:=nil; + FSecTbl:=nil; inherited destroy; end; @@ -2287,7 +2285,7 @@ const pemagic : array[0..3] of byte = ( InputError('Failed reading coff file, invalid section index'); exit; end; - result:=FSecTbl^[secidx]; + result:=FSecTbl[secidx]; end; @@ -2407,7 +2405,7 @@ const pemagic : array[0..3] of byte = ( end; end; - p:=FSymTbl^[rel.sym]; + p:=FSymTbl[rel.sym]; if assigned(p) then s.addsymreloc(rel.address-s.mempos,p,rel_type) else @@ -2456,7 +2454,7 @@ const pemagic : array[0..3] of byte = ( else nsyms:=FCoffSyms.Size div sizeof(CoffSymbol); { Allocate memory for symidx -> TObjSymbol table } - FSymTbl:=AllocMem(nsyms*sizeof(TObjSymbol)); + SetLength(FSymTbl,nsyms); { Load the Symbols } FCoffSyms.Seek(0); symidx:=0; @@ -2575,7 +2573,7 @@ const pemagic : array[0..3] of byte = ( else UnsupportedSymbolType; end; - FSymTbl^[symidx]:=objsym; + FSymTbl[symidx]:=objsym; { read aux records } { handle COMDAT symbols } @@ -2786,7 +2784,7 @@ const pemagic : array[0..3] of byte = ( FSecCount:=longint(boheader.NumberOfSections) else FSecCount:=header.nsects; - FSecTbl:=AllocMem((FSecCount+1)*sizeof(TObjSection)); + SetLength(FSecTbl,(FSecCount+1)); if bigobj then secofs:=sizeof(tcoffbigobjheader) else @@ -2849,7 +2847,7 @@ const pemagic : array[0..3] of byte = ( end; end; objsec:=TCoffObjSection(createsection(secname,secalign,secoptions,false)); - FSecTbl^[i]:=objsec; + FSecTbl[i]:=objsec; if not win32 then objsec.mempos:=sechdr.rvaofs; objsec.orgmempos:=sechdr.rvaofs;