Browse Source

* last commit was not complete, fixed

florian 1 year ago
parent
commit
7bbd33bcd6
1 changed files with 11 additions and 2 deletions
  1. 11 2
      compiler/nmem.pas

+ 11 - 2
compiler/nmem.pas

@@ -1361,14 +1361,23 @@ implementation
             case TStringConstNode(left).cst_type of
             case TStringConstNode(left).cst_type of
               cst_widestring, cst_unicodestring:
               cst_widestring, cst_unicodestring:
                 { value_str is of type PCompilerWideString }
                 { value_str is of type PCompilerWideString }
+
+                { while the conversion to PtrUInt is not correct when compiling from an 32 bit to a 64 bit platform because
+                  in theory for a 64 bit target the string could be longer than 2^32,
+                  it does not matter as a 32 bit host cannot handle such long strings anyways due to memory limitations
+                }
                 Result := COrdConstNode.create(
                 Result := COrdConstNode.create(
-                  PCompilerWideString(TStringConstNode(left).value_str)^.data[AWord(TOrdConstNode(right).value.uvalue) - 1],
+                  PCompilerWideString(TStringConstNode(left).value_str)^.data[PtrUInt(TOrdConstNode(right).value.uvalue) - 1],
                   resultdef,
                   resultdef,
                   False
                   False
                 );
                 );
               else
               else
+                { while the conversion to PtrUInt is not correct when compiling from an 32 bit to a 64 bit platform because
+                  in theory for a 64 bit target the string could be longer than 2^32,
+                  it does not matter as a 32 bit host cannot handle such long strings anyways due to memory limitations
+                }
                 Result := COrdConstNode.create(
                 Result := COrdConstNode.create(
-                  Byte(TStringConstNode(left).value_str[AWord(TOrdConstNode(right).value.uvalue) - 1]),
+                  Byte(TStringConstNode(left).value_str[PtrUInt(TOrdConstNode(right).value.uvalue) - 1]),
                   resultdef,
                   resultdef,
                   False
                   False
                 );
                 );