Browse Source

+ range checking for ansi- and widestrings
* made it compilable with TP

florian 26 years ago
parent
commit
9b3fd7f5b6
3 changed files with 92 additions and 20 deletions
  1. 7 2
      compiler/cg386cal.pas
  2. 7 2
      compiler/cg386mat.pas
  3. 78 16
      compiler/cg386mem.pas

+ 7 - 2
compiler/cg386cal.pas

@@ -849,7 +849,8 @@ implementation
 {$else TESTOBJEXT}
                    if (cs_check_range in aktlocalswitches) then
                      begin
-                        exprasmlist^.concat(new(pai386,op_csymbol(A_PUSH,S_L,newcsymbol(p^.procdefinition^._class^.vmt_mangledname,0))));
+                        exprasmlist^.concat(new(pai386,op_csymbol(A_PUSH,S_L,
+                          newcsymbol(p^.procdefinition^._class^.vmt_mangledname,0))));
                         exprasmlist^.concat(new(pai386,op_reg(A_PUSH,S_L,r^.base)));
                         emitcall('FPC_CHECK_OBJECT_EXT',true);
                      end;
@@ -1291,7 +1292,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.63  1999-02-03 10:18:14  pierre
+  Revision 1.64  1999-02-04 10:49:39  florian
+    + range checking for ansi- and widestrings
+    * made it compilable with TP
+
+  Revision 1.63  1999/02/03 10:18:14  pierre
    * conditionnal code for extended check of virtual methods
 
   Revision 1.62  1999/02/02 23:52:32  florian

+ 7 - 2
compiler/cg386mat.pas

@@ -622,7 +622,8 @@ implementation
                   exprasmlist^.concat(new(pai386,op_const_reg(A_XOR,opsize,1,p^.location.register)));}
                   p^.location.loc:=LOC_FLAGS;
                   p^.location.resflags:=F_E;
-                  exprasmlist^.concat(new(pai386,op_reg_reg(A_TEST,opsize,p^.left^.location.register,p^.left^.location.register)));
+                  exprasmlist^.concat(new(pai386,op_reg_reg(A_TEST,opsize,
+                    p^.left^.location.register,p^.left^.location.register)));
                   ungetregister(p^.left^.location.register);
                 end;
               LOC_CREGISTER :
@@ -762,7 +763,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.18  1999-02-03 10:11:12  pierre
+  Revision 1.19  1999-02-04 10:49:40  florian
+    + range checking for ansi- and widestrings
+    * made it compilable with TP
+
+  Revision 1.18  1999/02/03 10:11:12  pierre
    * fix for bug0211 for i386
 
   Revision 1.17  1999/01/21 22:10:41  peter

+ 78 - 16
compiler/cg386mem.pas

@@ -423,6 +423,15 @@ implementation
                         maybe_loadesi;
                         popusedregisters(pushed);
                      end;
+                   { check for a zero length ansistring }
+                   if (cs_check_range in aktlocalswitches) then
+                     begin
+                        pushusedregisters(pushed,$ff);
+                        exprasmlist^.concat(new(pai386,op_ref(A_PUSH,S_L,newreference(p^.left^.location.reference))));
+                        emitcall('FPC_ANSISTR_CHECKZERO',true);
+                        maybe_loadesi;
+                        popusedregisters(pushed);
+                     end;
                 end
               else
                 begin
@@ -434,6 +443,16 @@ implementation
                         maybe_loadesi;
                         popusedregisters(pushed);
                      end;
+                   { check for a zero length widestring,
+                     we can use the ansistring routine here }
+                   if (cs_check_range in aktlocalswitches) then
+                     begin
+                        pushusedregisters(pushed,$ff);
+                        exprasmlist^.concat(new(pai386,op_ref(A_PUSH,S_L,newreference(p^.left^.location.reference))));
+                        emitcall('FPC_ANSISTR_CHECKZERO',true);
+                        maybe_loadesi;
+                        popusedregisters(pushed);
+                     end;
                 end;
               del_reference(p^.left^.location.reference);
               p^.location.reference.base:=getregister32;
@@ -485,6 +504,7 @@ implementation
                    else
                      begin
                         { range checking for open arrays !!!! }
+                        {!!!!!!!!!!!!!!!!!}
                      end;
                 end
               else if (p^.left^.resulttype^.deftype=stringdef) then
@@ -492,23 +512,32 @@ implementation
                    if (p^.right^.value=0) and not(is_shortstring(p^.left^.resulttype)) then
                      CGMessage(cg_e_can_access_element_zero);
 
-                   case pstringdef(p^.left^.resulttype)^.string_typ of
-                      st_ansistring:
-                        begin
-                        end;
-
-                      st_shortstring:
-                        begin
-                        end;
+                   if (cs_check_range in aktlocalswitches) then
+                     case pstringdef(p^.left^.resulttype)^.string_typ of
+                        { it's the same for ansi- and wide strings }
+                        st_widestring,
+                        st_ansistring:
+                          begin
+                             pushusedregisters(pushed,$ff);
+                             push_int(p^.right^.value);
+                             hp:=newreference(p^.location.reference);
+                             dec(hp^.offset,7);
+                             exprasmlist^.concat(new(pai386,op_ref(A_PUSH,S_L,hp)));
+                             emitcall('FPC_ANSISTR_RANGECHECK',true);
+                             popusedregisters(pushed);
+                             maybe_loadesi;
+                          end;
 
-                      st_longstring:
-                        begin
-                        end;
+                        st_shortstring:
+                          begin
+                             {!!!!!!!!!!!!!!!!!}
+                          end;
 
-                      st_widestring:
-                        begin
-                        end;
-                   end;
+                        st_longstring:
+                          begin
+                             {!!!!!!!!!!!!!!!!!}
+                          end;
+                     end;
                 end;
 
               inc(p^.left^.location.reference.offset,
@@ -639,7 +668,36 @@ implementation
                       parraydef(p^.left^.resulttype)^.genrangecheck;
                       hp^.symbol:=stringdup(parraydef(p^.left^.resulttype)^.getrangecheckstring);
                       exprasmlist^.concat(new(pai386,op_reg_ref(A_BOUND,S_L,ind,hp)));
+                   end
+                 else if (p^.left^.resulttype^.deftype=stringdef) then
+                   begin
+                      case pstringdef(p^.left^.resulttype)^.string_typ of
+                         { it's the same for ansi- and wide strings }
+                         st_widestring,
+                         st_ansistring:
+                           begin
+                              pushusedregisters(pushed,$ff);
+                              exprasmlist^.concat(new(pai386,op_reg(A_PUSH,S_L,ind)));
+                              hp:=newreference(p^.location.reference);
+                              dec(hp^.offset,7);
+                              exprasmlist^.concat(new(pai386,op_ref(A_PUSH,S_L,hp)));
+                              emitcall('FPC_ANSISTR_RANGECHECK',true);
+                              popusedregisters(pushed);
+                              maybe_loadesi;
+                           end;
+
+                         st_shortstring:
+                           begin
+                              {!!!!!!!!!!!!!!!!!}
+                           end;
+
+                         st_longstring:
+                           begin
+                              {!!!!!!!!!!!!!!!!!}
+                           end;
+                      end;
                    end;
+
               end;
             if p^.location.reference.index=R_NO then
               begin
@@ -763,7 +821,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.25  1999-01-21 16:40:52  pierre
+  Revision 1.26  1999-02-04 10:49:41  florian
+    + range checking for ansi- and widestrings
+    * made it compilable with TP
+
+  Revision 1.25  1999/01/21 16:40:52  pierre
    * fix for constructor inside with statements
 
   Revision 1.24  1999/01/19 12:05:27  pierre