diff --git a/compiler/aasmcnst.pas b/compiler/aasmcnst.pas index 06dd962c27..5814318670 100644 --- a/compiler/aasmcnst.pas +++ b/compiler/aasmcnst.pas @@ -332,7 +332,7 @@ type { emit a shortstring constant, and return its def } function emit_shortstring_const(const str: shortstring): tdef; { emit a pchar string constant (the characters, not a pointer to them), and return its def } - function emit_pchar_const(str: pchar; len: pint): tdef; + function emit_pchar_const(str: pchar; len: pint; copypchar: boolean): tdef; { emit a guid constant } procedure emit_guid_const(const guid: tguid); { emit a procdef constant } @@ -1526,14 +1526,26 @@ implementation end; - function ttai_typedconstbuilder.emit_pchar_const(str: pchar; len: pint): tdef; + function ttai_typedconstbuilder.emit_pchar_const(str: pchar; len: pint; copypchar: boolean): tdef; + var + newstr: pchar; begin result:=carraydef.getreusable(cansichartype,len+1); maybe_begin_aggregate(result); - if len=0 then + if (len=0) and + (not assigned(str) or + copypchar) then emit_tai(Tai_const.Create_8bit(0),cansichartype) else - emit_tai(Tai_string.Create_pchar(str,len+1),result); + begin + if copypchar then + begin + getmem(newstr,len+1); + move(str^,newstr^,len+1); + str:=newstr; + end; + emit_tai(Tai_string.Create_pchar(str,len+1),result); + end; maybe_end_aggregate(result); end; diff --git a/compiler/objcgutl.pas b/compiler/objcgutl.pas index 838f085d63..a2e6a5aefd 100644 --- a/compiler/objcgutl.pas +++ b/compiler/objcgutl.pas @@ -166,7 +166,7 @@ procedure objcreatestringpoolentryintern(p: pchar; len: longint; pooltype: tcons { add the string to the approriate section } tcb:=ctai_typedconstbuilder.create([tcalo_is_lab,tcalo_new_section]); - def:=tcb.emit_pchar_const(pc,entry^.keylength); + def:=tcb.emit_pchar_const(pc,entry^.keylength,false); current_asmdata.asmlists[al_objc_pools].concatList( tcb.get_final_asmlist(strlab,def,stringsec,strlab.name,1) );