Recent

Author Topic: Overflow problem  (Read 180 times)

LemonParty

  • Hero Member
  • *****
  • Posts: 557
Overflow problem
« on: July 05, 2026, 05:57:45 pm »
Hello.

Here is the simplified code:
Code: Pascal  [Select][+][-]
  1.   for i:= 0 to Length(S) div BufSize do begin
  2.  
  3.     k:= Pred(Min(BufSize, SizeUInt(Length(S) - i * BufSize)) div BitSizeOf(SizeUInt));
  4.     for j:= 0 to Pred(Min(BufSize, SizeUInt(Length(S) - i * BufSize)) div BitSizeOf(SizeUInt)) do begin
  5.       Mask:= PSizeUInt(@MaskBuf[j * SizeOf(SizeUInt)])^;
  6.  
  7.     end;
  8.   end;
In this code I process a string by chunks and in some moment k becomes High(SizeUInt). The types of variables in this sample is SizeUInt. What I missing?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

jamie

  • Hero Member
  • *****
  • Posts: 7832
Re: Overflow problem
« Reply #1 on: July 05, 2026, 06:06:36 pm »
looks like you are using zero index.

The length of the loop should be one less /

for I := 0 To  Lenght(S)-1

The only true wisdom is knowing you know nothing

LemonParty

  • Hero Member
  • *****
  • Posts: 557
Re: Overflow problem
« Reply #2 on: July 05, 2026, 07:23:09 pm »
Changed
Code: Pascal  [Select][+][-]
  1. for i:= 0 to Length(S) div BufSize do begin
to
Code: Pascal  [Select][+][-]
  1. for i:= 0 to Pred(Length(S)) div BufSize do begin
Seems working.
Thank you.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

 

TinyPortal © 2005-2018