Browse Source

* do not crash when an unsupported code page is encountered, resolves #35581

git-svn-id: trunk@43764 -
florian 5 years ago
parent
commit
4de6b3e6b9
3 changed files with 25 additions and 2 deletions
  1. 1 0
      .gitattributes
  2. 8 2
      compiler/ncon.pas
  3. 16 0
      tests/webtbf/tw35581.pp

+ 1 - 0
.gitattributes

@@ -16091,6 +16091,7 @@ tests/webtbf/tw3502.pp svneol=native#text/plain
 tests/webtbf/tw35149a.pp svneol=native#text/plain
 tests/webtbf/tw35348.pp svneol=native#text/pascal
 tests/webtbf/tw3553.pp svneol=native#text/plain
+tests/webtbf/tw35581.pp svneol=native#text/pascal
 tests/webtbf/tw3562.pp svneol=native#text/plain
 tests/webtbf/tw35671.pp svneol=native#text/plain
 tests/webtbf/tw35753.pp svneol=native#text/plain

+ 8 - 2
compiler/ncon.pas

@@ -1067,7 +1067,10 @@ implementation
                       if (cp2=CP_UTF8) then
                         begin
                           if not cpavailable(cp1) then
-                            Message1(option_code_page_not_available,IntToStr(cp1));
+                            begin
+                              Message1(option_code_page_not_available,IntToStr(cp1));
+                              exit;
+                            end;
                           initwidestring(pw);
                           setlengthwidestring(pw,len);
                           { returns room for terminating 0 }
@@ -1086,7 +1089,10 @@ implementation
                       if (cp1=CP_UTF8) then
                         begin
                           if not cpavailable(cp2) then
-                            Message1(option_code_page_not_available,IntToStr(cp2));
+                            begin
+                              Message1(option_code_page_not_available,IntToStr(cp2));
+                              exit;
+                            end;
                           initwidestring(pw);
                           setlengthwidestring(pw,len);
                           ascii2unicode(value_str,len,cp2,pw);

+ 16 - 0
tests/webtbf/tw35581.pp

@@ -0,0 +1,16 @@
+{ %fail }
+{ %OPT=-Fcutf8 }
+program cps;
+
+{$mode objfpc}
+{$h+}
+
+type
+  Utf7String = type AnsiString(CP_UTF7);
+
+var
+  U7: Utf7String;
+
+begin
+  U7 := 'U7';
+end.