From fac96dd2ed2687f8bdf32dd448842f55dce748c7 Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 22 May 2004 23:33:18 +0000 Subject: [PATCH] fix range check error when array size > maxlongint --- compiler/cutils.pas | 31 ++++++++++++++++++++++++++++++- compiler/symdef.pas | 9 ++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/compiler/cutils.pas b/compiler/cutils.pas index b80eb12c5d..ec908ff992 100644 --- a/compiler/cutils.pas +++ b/compiler/cutils.pas @@ -39,8 +39,10 @@ interface {# Returns the minimal value between @var(a) and @var(b) } function min(a,b : longint) : longint;{$ifdef USEINLINE}inline;{$endif} + function min(a,b : int64) : int64;{$ifdef USEINLINE}inline;{$endif} {# Returns the maximum value between @var(a) and @var(b) } function max(a,b : longint) : longint;{$ifdef USEINLINE}inline;{$endif} + function max(a,b : int64) : int64;{$ifdef USEINLINE}inline;{$endif} {# Returns the value in @var(x) swapped to different endian } Function SwapInt64(x : int64): int64;{$ifdef USEINLINE}inline;{$endif} {# Returns the value in @var(x) swapped to different endian } @@ -152,6 +154,18 @@ uses end; + function min(a,b : int64) : int64;{$ifdef USEINLINE}inline;{$endif} + { + return the minimal of a and b + } + begin + if a>b then + min:=b + else + min:=a; + end; + + function max(a,b : longint) : longint;{$ifdef USEINLINE}inline;{$endif} { return the maximum of a and b @@ -164,6 +178,18 @@ uses end; + function max(a,b : int64) : int64;{$ifdef USEINLINE}inline;{$endif} + { + return the maximum of a and b + } + begin + if a maxlongint + + Revision 1.38 2004/03/29 19:19:35 florian + arm floating point register saving implemented * hopefully stabs generation for MacOSX fixed + some defines for arm added diff --git a/compiler/symdef.pas b/compiler/symdef.pas index c182c9dac3..25bd9d0d2f 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -3004,9 +3004,9 @@ implementation write_rtti_name; { size of elements } rttiList.concat(Tai_const.Create_32bit(elesize)); - { count of elements } + { count of elements, prevent overflow for 0..maxlongint } if not(IsDynamicArray) then - rttiList.concat(Tai_const.Create_32bit(highrange-lowrange+1)); + rttiList.concat(Tai_const.Create_32bit(min(int64(highrange)-lowrange+1,maxlongint))); { element type } rttiList.concat(Tai_const_symbol.Create(tstoreddef(elementtype.def).get_rtti_label(rt))); { variant type } @@ -6184,7 +6184,10 @@ implementation end. { $Log$ - Revision 1.236 2004-05-01 22:05:01 florian + Revision 1.237 2004-05-22 23:33:18 peter + fix range check error when array size > maxlongint + + Revision 1.236 2004/05/01 22:05:01 florian + added lib support for Amiga/MorphOS syscalls Revision 1.235 2004/04/29 19:56:37 daniel