diff --git a/compiler/ncgmem.pas b/compiler/ncgmem.pas index fd60b8fb02..cad56ab507 100644 --- a/compiler/ncgmem.pas +++ b/compiler/ncgmem.pas @@ -699,8 +699,6 @@ implementation var paraloc1, paraloc2: tcgpara; - href: treference; - offsetdec: aint; begin paraloc1.init; paraloc2.init; @@ -712,26 +710,9 @@ implementation begin paramanager.getintparaloc(pocall_default,1,paraloc1); paramanager.getintparaloc(pocall_default,2,paraloc2); + cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,left.location,paraloc1); cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,right.location,paraloc2); - href:=location.reference; - { Add back the offset which was subtracted to map string[1]->pchar(string)[0] } - { TODO: we'd better rangecheck on the original location, before offsetting it. } - if is_ansistring(left.resultdef) then - offsetdec:=1 - else - offsetdec:=2; - if not(tf_winlikewidestring in target_info.flags) or - (tstringdef(left.resultdef).stringtype<>st_widestring) then - begin - dec(href.offset,sizeof(pint)-offsetdec); - cg.a_load_ref_cgpara(current_asmdata.CurrAsmList,OS_ADDR,href,paraloc1); - end - else - begin - { winlike widestrings have a 4 byte length } - dec(href.offset,4-offsetdec); - cg.a_load_ref_cgpara(current_asmdata.CurrAsmList,OS_32,href,paraloc1); - end; + paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1); paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc2); cg.allocallcpuregisters(current_asmdata.CurrAsmList); @@ -788,8 +769,7 @@ implementation { an ansistring needs to be dereferenced } if is_ansistring(left.resultdef) or - is_widestring(left.resultdef) or - is_unicodestring(left.resultdef) then + is_wide_or_unicode_string(left.resultdef) then begin if nf_callunique in flags then internalerror(200304236); @@ -816,18 +796,6 @@ implementation internalerror(2002032218); end; - { check for a zero length string, - we can use the ansistring routine here } - if (cs_check_range in current_settings.localswitches) then - begin - paramanager.getintparaloc(pocall_default,1,paraloc1); - cg.a_load_reg_cgpara(current_asmdata.CurrAsmList,OS_ADDR,location.reference.base,paraloc1); - paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1); - cg.allocallcpuregisters(current_asmdata.CurrAsmList); - cg.a_call_name(current_asmdata.CurrAsmList,'FPC_'+upper(tstringdef(left.resultdef).stringtypname)+'_CHECKZERO',false); - cg.deallocallcpuregisters(current_asmdata.CurrAsmList); - end; - { in ansistrings/widestrings S[1] is pchar(S)[0] !! } if is_ansistring(left.resultdef) then offsetdec:=1 diff --git a/rtl/inc/astrings.inc b/rtl/inc/astrings.inc index 1d6d4253c1..d4d8caa823 100644 --- a/rtl/inc/astrings.inc +++ b/rtl/inc/astrings.inc @@ -539,16 +539,10 @@ begin end; -Procedure fpc_AnsiStr_CheckZero(p : pointer);[Public,Alias : 'FPC_ANSISTR_CHECKZERO']; compilerproc; -begin - if p=nil then - HandleErrorFrame(201,get_frame); -end; - -Procedure fpc_AnsiStr_CheckRange(len,index : SizeInt);[Public,Alias : 'FPC_ANSISTR_RANGECHECK']; compilerproc; +Procedure fpc_AnsiStr_CheckRange(p: Pointer; index: SizeInt);[Public,Alias : 'FPC_ANSISTR_RANGECHECK']; compilerproc; begin - if (index>len) or (Index<1) then + if (p=nil) or (index>PAnsiRec(p-FirstOff)^.Len) or (Index<1) then HandleErrorFrame(201,get_frame); end; diff --git a/rtl/inc/compproc.inc b/rtl/inc/compproc.inc index 90f4dbb5cf..c80e3699aa 100644 --- a/rtl/inc/compproc.inc +++ b/rtl/inc/compproc.inc @@ -278,8 +278,7 @@ procedure fpc_ansistr_to_chararray(out res: array of char; const src: ansistring {$endif ndef FPC_STRTOCHARARRAYPROC} Function fpc_AnsiStr_Compare(const S1,S2 : AnsiString): SizeInt; compilerproc; Function fpc_AnsiStr_Compare_equal(const S1,S2 : AnsiString): SizeInt; compilerproc; -Procedure fpc_AnsiStr_CheckZero(p : pointer); compilerproc; -Procedure fpc_AnsiStr_CheckRange(len,index : SizeInt); compilerproc; +Procedure fpc_AnsiStr_CheckRange(p : Pointer; index : SizeInt); compilerproc; Procedure fpc_AnsiStr_SetLength (Var S : AnsiString; l : SizeInt); compilerproc; Function fpc_ansistr_Copy (Const S : AnsiString; Index,Size : SizeInt) : AnsiString;compilerproc; {$ifdef EXTRAANSISHORT} @@ -327,8 +326,7 @@ procedure fpc_widestr_to_widechararray(out res: array of widechar; const src: Wi {$endif ndef FPC_STRTOCHARARRAYPROC} Function fpc_WideStr_Compare(const S1,S2 : WideString): SizeInt; compilerproc; Function fpc_WideStr_Compare_equal(const S1,S2 : WideString): SizeInt; compilerproc; -Procedure fpc_WideStr_CheckZero(p : pointer); compilerproc; -Procedure fpc_WideStr_CheckRange(len,index : SizeInt); compilerproc; +Procedure fpc_WideStr_CheckRange(p: Pointer; index : SizeInt); compilerproc; Procedure fpc_WideStr_SetLength (Var S : WideString; l : SizeInt); compilerproc; Function fpc_widestr_Copy (Const S : WideString; Index,Size : SizeInt) : WideString;compilerproc; {$ifndef FPC_WINLIKEWIDESTRING} @@ -413,8 +411,7 @@ procedure fpc_unicodestr_to_widechararray(out res: array of widechar; const src: {$endif VER2_2} Function fpc_UnicodeStr_Compare(const S1,S2 : UnicodeString): SizeInt; compilerproc; Function fpc_UnicodeStr_Compare_equal(const S1,S2 : UnicodeString): SizeInt; compilerproc; -Procedure fpc_UnicodeStr_CheckZero(p : pointer); compilerproc; -Procedure fpc_UnicodeStr_CheckRange(len,index : SizeInt); compilerproc; +Procedure fpc_UnicodeStr_CheckRange(p: Pointer; index : SizeInt); compilerproc; Procedure fpc_UnicodeStr_SetLength (Var S : UnicodeString; l : SizeInt); compilerproc; Function fpc_unicodestr_Copy (Const S : UnicodeString; Index,Size : SizeInt) : UnicodeString;compilerproc; function fpc_unicodestr_Unique(Var S : Pointer): Pointer; compilerproc; diff --git a/rtl/inc/ustrings.inc b/rtl/inc/ustrings.inc index f805d376f1..ed7e3583a9 100644 --- a/rtl/inc/ustrings.inc +++ b/rtl/inc/ustrings.inc @@ -1304,16 +1304,10 @@ begin exit(CompareWord(S1[1],S2[1],MaxI)); end; -Procedure fpc_UnicodeStr_CheckZero(p : pointer);[Public,Alias : 'FPC_UNICODESTR_CHECKZERO']; compilerproc; -begin - if p=nil then - HandleErrorFrame(201,get_frame); -end; - -Procedure fpc_UnicodeStr_CheckRange(len,index : SizeInt);[Public,Alias : 'FPC_UNICODESTR_RANGECHECK']; compilerproc; +Procedure fpc_UnicodeStr_CheckRange(p: Pointer; index: SizeInt);[Public,Alias : 'FPC_UNICODESTR_RANGECHECK']; compilerproc; begin - if (index>len div 2) or (Index<1) then + if (p=nil) or (index>PUnicodeRec(p-UnicodeFirstOff)^.len div 2) or (Index<1) then HandleErrorFrame(201,get_frame); end; diff --git a/rtl/inc/wstrings.inc b/rtl/inc/wstrings.inc index fe573bf12c..f0fa4572a4 100644 --- a/rtl/inc/wstrings.inc +++ b/rtl/inc/wstrings.inc @@ -729,16 +729,10 @@ begin exit(CompareWord(S1[1],S2[1],MaxI)); end; -Procedure fpc_WideStr_CheckZero(p : pointer);[Public,Alias : 'FPC_WIDESTR_CHECKZERO']; compilerproc; -begin - if p=nil then - HandleErrorFrame(201,get_frame); -end; - -Procedure fpc_WideStr_CheckRange(len,index : SizeInt);[Public,Alias : 'FPC_WIDESTR_RANGECHECK']; compilerproc; +Procedure fpc_WideStr_CheckRange(p: Pointer; index: SizeInt);[Public,Alias : 'FPC_WIDESTR_RANGECHECK']; compilerproc; begin - if (index>len div 2) or (Index<1) then + if (p=nil) or (index>PWideRec(p-WideFirstOff)^.len div 2) or (Index<1) then HandleErrorFrame(201,get_frame); end;