Recent

Author Topic: [SOLVED]cmem.CFreeMemSize possible error  (Read 229 times)

BrunoK

  • Sr. Member
  • ****
  • Posts: 275
  • Retired programmer
[SOLVED]cmem.CFreeMemSize possible error
« on: January 13, 2022, 07:23:25 pm »
FPC 3.2.2 and 3.0.4

in \rtl\inc\cmem.pp

It seems to me that :
Code: Pascal  [Select][+][-]
  1. Function CFreeMemSize(p:pointer;Size:ptruint):ptruint;
  2.  
  3. begin
  4.   if size<=0 then
  5.     exit;
  6.   if (p <> nil) then
  7.     begin
  8.       if (size <> Pptruint(p-sizeof(ptruint))^) then
  9.         runerror(204);
  10.     end;
  11.   CFreeMemSize:=CFreeMem(P);
  12. end;
  13.  

should be
Code: Pascal  [Select][+][-]
  1. Function CFreeMemSize(p:pointer;Size:ptruint):ptruint;
  2.  
  3. begin
  4.   if size<=0 then
  5.     exit;
  6.   if (p <> nil) then
  7.     begin
  8.       if (size <> Pptruint(p-sizeof(ptruint))^) then
  9.         runerror(204);
  10.       dec(p,sizeof(ptruint)); // <<<<------ here
  11.     end;
  12.   CFreeMemSize:=CFreeMem(P);
  13. end;
  14.  
The dec(p,sizeof(ptruint)); seems to be missing to get the pointer to pass to cmem CFreeMem library function.

What do you think ?

It seems to have no consequence because it is apparently never called by fpc or lazarus but it looks anyway like a possible bug.
« Last Edit: January 13, 2022, 07:31:52 pm by BrunoK »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 936
Re: cmem.CFreeMemSize possible error
« Reply #1 on: January 13, 2022, 07:25:25 pm »
CFreeMem does that dec already (it's a Pascal routine defined in the same unit, not the C library "free").

BrunoK

  • Sr. Member
  • ****
  • Posts: 275
  • Retired programmer
Re: cmem.CFreeMemSize possible error
« Reply #2 on: January 13, 2022, 07:30:30 pm »
Yes sir ! Sorry, my bad.

I didn't notice that it was calling an 'internal' CFreeMem procedure.
 

 

TinyPortal © 2005-2018