Browse Source

* fixed const pchar

peter 27 years ago
parent
commit
2ce832e18e
1 changed files with 17 additions and 10 deletions
  1. 17 10
      compiler/ptconst.pas

+ 17 - 10
compiler/ptconst.pas

@@ -187,13 +187,16 @@ unit ptconst;
                     datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(ll)))));
                     datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(ll)))));
                     consts^.concat(new(pai_label,init(ll)));
                     consts^.concat(new(pai_label,init(ll)));
                     if p^.treetype=stringconstn then
                     if p^.treetype=stringconstn then
-                      consts^.concat(new(pai_string,init(p^.value_str^+#0)))
+                      begin
+                        getmem(ca,p^.length+2);
+                        move(p^.value_str^,ca^,p^.length+1);
+                        generate_pascii(consts,ca,p^.length+1);
+                      end
                     else
                     else
                       if is_constcharnode(p) then
                       if is_constcharnode(p) then
                         consts^.concat(new(pai_string,init(char(byte(p^.value))+#0)))
                         consts^.concat(new(pai_string,init(char(byte(p^.value))+#0)))
                     else
                     else
                       Message(cg_e_illegal_expression);
                       Message(cg_e_illegal_expression);
-                    { insert label }
                 end
                 end
               else
               else
                 if p^.treetype=addrn then
                 if p^.treetype=addrn then
@@ -318,8 +321,7 @@ unit ptconst;
                            datasegment^.concat(new(pai_const,init_8bit(strlength)));
                            datasegment^.concat(new(pai_const,init_8bit(strlength)));
                            { this can also handle longer strings }
                            { this can also handle longer strings }
                            getmem(ca,strlength+1);
                            getmem(ca,strlength+1);
-                           move(p^.value_str^,ca^,strlength);
-                           ca[strlength]:=#0;
+                           move(p^.value_str^,ca^,strlength+1);
                            generate_pascii(datasegment,ca,strlength);
                            generate_pascii(datasegment,ca,strlength);
                         end
                         end
                       else if is_constcharnode(p) then
                       else if is_constcharnode(p) then
@@ -331,15 +333,17 @@ unit ptconst;
 
 
                       if def^.size>strlength then
                       if def^.size>strlength then
                         begin
                         begin
-                           getmem(ca,def^.size-strlength);
+                           getmem(ca,def^.size-strlength+1);
                            { def^.size contains also the leading length, so we }
                            { def^.size contains also the leading length, so we }
                            { we have to subtract one                           }
                            { we have to subtract one                           }
                            fillchar(ca[0],def^.size-strlength-1,' ');
                            fillchar(ca[0],def^.size-strlength-1,' ');
                            ca[def^.size-strlength-1]:=#0;
                            ca[def^.size-strlength-1]:=#0;
                            { this can also handle longer strings }
                            { this can also handle longer strings }
-                           generate_pascii(datasegment,ca,def^.size-strlength-1);
-                        end;
-                    end;
+                           generate_pascii(datasegment,ca,def^.size-strlength);
+                        end
+                      else
+                        datasegment^.concat(new(pai_const,init_8bit(0)));
+                   end;
 {$ifdef UseLongString}
 {$ifdef UseLongString}
                  st_longstring:
                  st_longstring:
                    begin
                    begin
@@ -405,7 +409,7 @@ unit ptconst;
                            else Message(cg_e_illegal_expression);
                            else Message(cg_e_illegal_expression);
                            consts^.concat(new(pai_const,init_8bit(0)));
                            consts^.concat(new(pai_const,init_8bit(0)));
                         end;
                         end;
-                    end;
+                   end;
               end;
               end;
               disposetree(p);
               disposetree(p);
            end;
            end;
@@ -624,7 +628,10 @@ unit ptconst;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.24  1998-11-05 12:02:55  peter
+  Revision 1.25  1998-11-10 16:10:47  peter
+    * fixed const pchar
+
+  Revision 1.24  1998/11/05 12:02:55  peter
     * released useansistring
     * released useansistring
     * removed -Sv, its now available in fpc modes
     * removed -Sv, its now available in fpc modes