Quellcode durchsuchen

* don't crash when someone uses an integer value to declare a wide/unicode
string (mantis #12329)

git-svn-id: trunk@11875 -

Jonas Maebe vor 17 Jahren
Ursprung
Commit
79850c5027
3 geänderte Dateien mit 26 neuen und 2 gelöschten Zeilen
  1. 1 0
      .gitattributes
  2. 8 2
      compiler/ptconst.pas
  3. 17 0
      tests/webtbf/tw12329.pp

+ 1 - 0
.gitattributes

@@ -8109,6 +8109,7 @@ tests/webtbf/tw11846c.pp svneol=native#text/plain
 tests/webtbf/tw11848a.pp svneol=native#text/plain
 tests/webtbf/tw11849a.pp svneol=native#text/plain
 tests/webtbf/tw11862a.pp svneol=native#text/plain
+tests/webtbf/tw12329.pp svneol=native#text/plain
 tests/webtbf/tw1238.pp svneol=native#text/plain
 tests/webtbf/tw1251a.pp svneol=native#text/plain
 tests/webtbf/tw1270.pp svneol=native#text/plain

+ 8 - 2
compiler/ptconst.pas

@@ -646,8 +646,14 @@ implementation
               { convert to the expected string type so that
                 for widestrings strval is a pcompilerwidestring }
               inserttypeconv(n,def);
-              strlength:=tstringconstnode(n).len;
-              strval:=tstringconstnode(n).value_str;
+              if not codegenerror then
+                begin
+                  strlength:=tstringconstnode(n).len;
+                  strval:=tstringconstnode(n).value_str;
+                end
+              else
+                { an error occurred trying to convert the result to a string }
+                strlength:=-1;
             end
           else if is_constcharnode(n) then
             begin

+ 17 - 0
tests/webtbf/tw12329.pp

@@ -0,0 +1,17 @@
+{ %fail }
+
+unit tw12329;
+{$mode objfpc}{$h+}
+
+interface
+
+implementation
+
+procedure test;
+const
+  arr: array[0..1] of WideString = (0, 0);
+begin
+
+end;
+
+end.