Is this a bug in compiler widestr.unicode2ascii lazarus / 64-FPC development ---------------------------------------------------------------------- engkin · 2018-05-13 17:17 Unit widestr has a function unicode2ascii: 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     procedure unicode2ascii(r : pcompilerwidestring;p:pchar;cp : tstringencoding);      var        m : punicodemap;        source : tcompilerwidecharptr;        dest   : pchar;        i      : longint;      begin        { can't implement that here, because the memory size for p() cannot          be changed here, and we may need more bytes than have been allocated }        if cp=CP_UTF8 then          internalerrorproc(2015092701);         if (cp = 0) or (cp=CP_NONE) then          m:=getmap(current_settings.sourcecodepage)... The function makes sure that cp is not CP_UTF8, but later on it does not do the same check for current_settings.sourcecodepage which is also possible to be CP_UTF8. Is this a bug? ---------------------------------------------------------------------- Thaddy · 2018-05-14 07:45 No, because if cp happens to be UTF8 that code will never execute, because the internalerrorproc prevents that. ---------------------------------------------------------------------- engkin · 2018-05-15 04:39 Quote from: Thaddy on May 14, 2018, 09:45:50 amNo, because if cp happens to be UTF8 that code will never execute, because the internalerrorproc prevents that. The bug that I see is in the highlighted lines: 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     procedure unicode2ascii(r : pcompilerwidestring;p:pchar;cp : tstringencoding);      var        m : punicodemap;        source : tcompilerwidecharptr;        dest   : pchar;        i      : longint;      begin        { can't implement that here, because the memory size for p() cannot          be changed here, and we may need more bytes than have been allocated }        if cp=CP_UTF8 then          internalerrorproc(2015092701);         if (cp = 0) or (cp=CP_NONE) then          m:=getmap(current_settings.sourcecodepage)... The bug happens when cp is 0 or CP_NONE AND sourcecodepage is CP_UTF8. This procedure can not convert to UTF8. ---------------------------------------------------------------------- Thaddy · 2018-05-15 06:42 @getmem I am trying to force that bug but did not succeed yet in reproducing it. Do you have an example? ---------------------------------------------------------------------- engkin · 2018-05-20 23:02 Quote from: Thaddy on May 15, 2018, 08:42:19 amI am trying to force that bug but did not succeed yet in reproducing it. Do you have an example? Thank you Thaddy for trying. The procedure is used in two places (at this time), both protect it from this bug. So there is no visible bug related to this procedure, yet. But it does have a logical error.