2
0
Эх сурвалжийг харах

* fixed web bug #1396: tpointerord is now a cardinal instead of a longint,
but added a hack in ncnv so that pointer(-1) still works

Jonas Maebe 24 жил өмнө
parent
commit
74c1d32ce9

+ 10 - 2
compiler/i386/cpuinfo.pas

@@ -37,7 +37,11 @@ Type
    { this must be an ordinal type with the same size as a pointer }
    { to allow some dirty type casts for example when using        }
    { tconstsym.value                                              }
-   TPointerOrd = longint;
+   { Note: must be unsigned!! Otherwise, ugly code like           }
+   { pointer(-1) will result in a pointer with the value          }
+   { $fffffffffffffff on a 32bit machine if the compiler uses     }
+   { int64 constants internally (JM)                              }
+   TPointerOrd = cardinal;
 
 Const
    { Size of native extended type }
@@ -48,7 +52,11 @@ Implementation
 end.
 {
   $Log$
-  Revision 1.1  2000-10-15 09:39:37  peter
+  Revision 1.2  2001-02-08 13:09:03  jonas
+    * fixed web bug 1396: tpointerord is now a cardinal instead of a longint,
+      but added a hack in ncnv so that pointer(-1) still works
+
+  Revision 1.1  2000/10/15 09:39:37  peter
     * moved cpu*.pas to i386/
     * renamed n386 to common cpunode
 

+ 23 - 3
compiler/ncnv.pas

@@ -96,7 +96,7 @@ implementation
 {$else newcg}
       hcodegen,
 {$endif newcg}
-      htypechk,pass_1,cpubase;
+      htypechk,pass_1,cpubase,cpuinfo;
 
 
     function gentypeconvnode(node : tnode;t : pdef) : ttypeconvnode;
@@ -657,7 +657,23 @@ implementation
         first_cord_to_pointer:=nil;
         if left.nodetype=ordconstn then
           begin
-            t:=genpointerconstnode(tordconstnode(left).value,resulttype);
+            { check if we have a valid pointer constant (JM) }
+            if (sizeof(tordconstnode) > sizeof(tpointerord)) then
+              if (sizeof(tpointerord) = 4) then
+                begin
+                  if (tordconstnode(left).value < low(longint)) or
+                     (tordconstnode(left).value > high(cardinal)) then
+                  CGMessage(parser_e_range_check_error);
+                end
+              else if (sizeof(tpointerord) = 8) then
+                begin
+                  if (tordconstnode(left).value < low(int64)) or
+                     (tordconstnode(left).value > high(qword)) then
+                  CGMessage(parser_e_range_check_error);
+                end
+              else
+                internalerror(2001020801);
+            t:=genpointerconstnode(tpointerord(tordconstnode(left).value),resulttype);
             firstpass(t);
             first_cord_to_pointer:=t;
             exit;
@@ -1203,7 +1219,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.16  2000-12-31 11:14:10  jonas
+  Revision 1.17  2001-02-08 13:09:03  jonas
+    * fixed web bug 1396: tpointerord is now a cardinal instead of a longint,
+      but added a hack in ncnv so that pointer(-1) still works
+
+  Revision 1.16  2000/12/31 11:14:10  jonas
     + implemented/fixed docompare() mathods for all nodes (not tested)
     + nopt.pas, nadd.pas, i386/n386opt.pas: optimized nodes for adding strings
       and constant strings/chars together