FPC 3.2.2 + GDB lazarus / 21-General ---------------------------------------------------------------------- paule32 · 2025-05-19 06:13 what is the error ? - a range overflow ? Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Thread 1 received signal SIGSEGV, Segmentation fault.0x00000001100041ee in STRCAT_ (DEST=0x11000a5e8 '1', SOURCE=0x110007a38 '') at SysUtils.pas:216216       D[i + J + 2] := #0;(gdb)This is the source code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function StrCat_(var Dest: PChar; Source: PChar): PChar; stdcall; export;var  D       : PChar;  L, I, J : Integer;begin  L := StrLen(Dest) + StrLen(Source) + 1;  D := StrAlloc(L);    for i := 0 to StrLen(Dest) - 1 do  D[i] := Dest[i];    for J := 0 to StrLen(Source) - 1 do  D[i + j + 1] := Source[J];  D[i + J + 2] := #0;    Dest := D;  Exit(D);end; ---------------------------------------------------------------------- 440bx · 2025-05-19 06:39 In a Pascal "for" loop the value of the index variable, in your case "i", is undefined when the loop ends. Therefore, the lines 13 and 14 of your code are using a value which could be anything.  That's the reason you are getting a violation. If you need to depend on the value of "i" when the loop ends, change it from a "for" to a "while" where you update the index yourself. HTH. ---------------------------------------------------------------------- H₂SO₄ · 2025-05-19 06:41 Like @440bx said, you cannot just use  i  and  j  after their respective loops have exited. And if you want to be really pedantic, you shouldn't reuse the loop variable for anything else either; just for the loop itself. This has been discussed to death numerous times. Also there's no reason to call  StrLen  twice for each parameter - you should cache the results. ---------------------------------------------------------------------- paule32 · 2025-05-19 07:14 Thanks for replies: In my case, Source was empty/null, so I had add two conditionals that check the Dest and Source Arguments. And I use repeat until instead while. So, the result will work, now. Thank you. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function StrCat(var Dest: PChar; Source: PChar): PChar; stdcall; export;var  D     : PChar;  L, I, J : Integer;begin  if Dest = nil then  begin    MessageBoxA(0,'Error: StrCat Dest not initialized.','Error',0);    Exit;  end;   if Strlen(Source) < 1 then  begin    Dest := '';    Exit(Dest);  end;    L := StrLen(Dest) + StrLen(Source) + 1;  D := StrAlloc(L);    L := StrLen(Dest);  i := 0;  repeat    D[i] := Dest[i];    inc(i);  until i = L;    L := StrLen(Source);  j := 0;  repeat    D[i + j] := Source[j];    inc(j);  until j = L;   D[i + j] := #0;  Dest := D;    Exit(D);end; ---------------------------------------------------------------------- marcov · 2025-05-19 09:27 And of course not caching strlen's.  Contrary to length() on Pascal strings, Strlen on zero terminated strings is an expensive operation.