diff --git a/.gitattributes b/.gitattributes index 5bec94b3c3..02e9b84edd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16408,6 +16408,7 @@ tests/webtbs/tw33607.pp svneol=native#text/plain tests/webtbs/tw33635.pp svneol=native#text/pascal tests/webtbs/tw3364.pp svneol=native#text/plain tests/webtbs/tw3366.pp svneol=native#text/plain +tests/webtbs/tw33666.pp svneol=native#text/plain tests/webtbs/tw33696.pp svneol=native#text/pascal tests/webtbs/tw33700.pp svneol=native#text/pascal tests/webtbs/tw33706.pp svneol=native#text/plain diff --git a/compiler/ncon.pas b/compiler/ncon.pas index ae94637c28..6a048420ff 100644 --- a/compiler/ncon.pas +++ b/compiler/ncon.pas @@ -982,6 +982,7 @@ implementation Message1(option_code_page_not_available,IntToStr(cp1)); initwidestring(pw); setlengthwidestring(pw,len); + { returns room for terminating 0 } l:=Utf8ToUnicode(PUnicodeChar(pw^.data),len,value_str,len); if (l<>getlengthwidestring(pw)) then begin @@ -989,6 +990,7 @@ implementation ReAllocMem(value_str,l); end; unicode2ascii(pw,value_str,cp1); + len:=l-1; donewidestring(pw); end else @@ -1000,6 +1002,7 @@ implementation initwidestring(pw); setlengthwidestring(pw,len); ascii2unicode(value_str,len,cp2,pw); + { returns room for terminating 0 } l:=UnicodeToUtf8(nil,0,PUnicodeChar(pw^.data),len); if l<>len then ReAllocMem(value_str,l); diff --git a/tests/webtbs/tw33666.pp b/tests/webtbs/tw33666.pp new file mode 100644 index 0000000000..9127dd476b --- /dev/null +++ b/tests/webtbs/tw33666.pp @@ -0,0 +1,16 @@ +program Project1; + +{$mode objfpc}{$H+} +{$Codepage UTF8} + +type + CP437String = type ansistring(437); + +var + s_cp437_1: CP437String; +begin + s_cp437_1 := '║'; //<--- buggy + if (length(s_cp437_1)<> 1) or + (ord(s_cp437_1[1])<> 186) then + halt(1); +end.