[SOLVED] Improvement of function SetCompileModeSwitch lazarus / 64-FPC development ---------------------------------------------------------------------- lagprogramming · 2023-11-19 07:33 compiler/scanner.pas has function SetCompileModeSwitch(s:string; changeInit: boolean):boolean; Within the code of the function "s:=copy(s,1,length(s)-1);" can be encountered twice. The attached patch replaces it with "setlength(s,length(s)-1);". ---------------------------------------------------------------------- AlexTP · 2023-11-19 07:56 Reported to https://gitlab.com/freepascal.org/fpc/source/-/issues/40525 ---------------------------------------------------------------------- vangli · 2023-11-19 08:12 Hi. Just of curriosity. Isn't it? 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 s:=copy(s,1,length(s)-1); will guaranty that "s" is minimum an empty string if it happens that "s" is single byte or already an empty string. 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 setlength(s,length(s)-1); will release memory if "s" is one byte long or already an empty string. Then the rest of the function SetCompileModeSwitch will crash? ---------------------------------------------------------------------- TRon · 2023-11-19 08:34 Quote from: vangli on November 19, 2023, 09:12:35 amwill release memory if "s" is one byte long or already an empty string. Then the rest of the function SetCompileModeSwitch will crash? Nah, not really  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 case s[length(s)] of ---------------------------------------------------------------------- vangli · 2023-11-19 08:53 Thks TRon. I may have been (mis)leaded by https://www.freepascal.org/docs-html/rtl/system/setlength.html where it states the following: "Note that SetLength is governed by the Copy-On-Write principle for strings and dynamic arrays: the reference count after a call to SetLength will be 1 (except when the length is zero, then the array is removed from memory). " I read the parenthesis to include both strings and arrays, but it may only be true for array length.