Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2001-01

Range check error?!

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

C.Keck

Hi,

I have some problems with a little CRC-calculation routine I ported from some C code. The FPC version gives a range check error, but I can't find the reason for this... Here's the source:

function build_edc (var inout : array of byte; from, upto : integer) : longint;
var i : integer;
begin
  build_edc:= 0;
  for i:= from to upto-1 do
    build_edc:= EDC_crctable[(build_edc xor inout[i]) and $FF] xor (build_edc shr 8);
end;

FYI: EDC_crctable[] is an array with longint values

Could somebody please help me?
Many thanks in advance!

C.Keck

Reply by email

Tobias Hermann
to C.Keck

try to break up the line

      build_edc:= EDC_crctable[(build_edc xor inout[i]) and $FF] xor
(build_edc shr 8);

into more single lines with single operations. use temporary variables... so you can see where exactly the error occurs...
Then pse post again...

Tobi

Earlier message 33 lines
----- Original Message ----- From: C.Keck To: Sent: Saturday, January 27, 2001 12:36 AM Subject: [fpc-devel]Range check error?! > Hi, > > I have some problems with a little CRC-calculation routine I ported from some C code. > The FPC version gives a range check error, but I can't find the reason for this... > Here's the source: > > function build_edc (var inout : array of byte; from, upto : integer) : longint; > > var i : integer; > > begin > build_edc:= 0; > for i:= from to upto-1 do > build_edc:= EDC_crctable[(build_edc xor inout[i]) and $FF] xor (build_edc shr 8); > end; > > FYI: EDC_crctable[] is an array with longint values > > Could somebody please help me? > Many thanks in advance! > > C.Keck

Reply by email

Peter Vreman
to C.Keck: I have some problems with a little CRC-calculation routine I ported from some C code. The…
Show quoted text 18 lines
I have some problems with a little CRC-calculation routine I ported from some C code. The FPC version gives a range check error, but I can't find the reason for this... Here's the source: function build_edc (var inout : array of byte; from, upto : integer) : longint; var i : integer; begin build_edc:= 0; for i:= from to upto-1 do build_edc:= EDC_crctable[(build_edc xor inout[i]) and $FF] xor (build_edc shr 8); end; FYI: EDC_crctable[] is an array with longint values Could somebody please help me? Many thanks in advance!

crcs are cardinal values (0-$ffffffff).

Reply by email

Jonas Maebe
to C.Keck: I have some problems with a little CRC-calculation routine I ported from some C code. The…
C.Keck wrote 11 lines
function build_edc (var inout : array of byte; from, upto : integer) : longint; var i : integer; begin build_edc:= 0; for i:= from to upto-1 do build_edc:= EDC_crctable[(build_edc xor inout[i]) and $FF] xor (build_edc shr 8); end; FYI: EDC_crctable[] is an array with longint values

Are you sure it isn't an array of cardinal? Because in that case, itf the result is > $7fffffff, then it's bigger than maxlongint and you'll get a range error when assigning the result to build_edc.

Jonas

Reply by email

C.Keck

Original message from: Jonas Maebe

Show quoted text 21 lines
On Sat, 27 Jan 2001, C.Keck wrote: > function build_edc (var inout : array of byte; from, upto : integer) : longint; > > var i : integer; > > begin > build_edc:= 0; > for i:= from to upto-1 do > build_edc:= EDC_crctable[(build_edc xor inout[i]) and $FF] xor (build_edc shr 8); > end; > > FYI: EDC_crctable[] is an array with longint values Are you sure it isn't an array of cardinal? Because in that case, itf the result is > $7fffffff, then it's bigger than maxlongint and you'll get a range error when assigning the result to build_edc. Jonas

Thanks for the help! Meanwhile I found the bug: The function was called with some wrong parameters by another function... However, I was able to fix this now ;)

Chris

Reply by email