Sign in Join

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

Mailing lists / fpc-pascal / 2004-07

Error running gdbmtest2.pp

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Christian Müllerke

Hi!

Maybe I'd found a bug in gdbm.pp I'm running Linux (2.6.7) and fpc-1.9.4:

fpctest2 $ ./testgdbm2
Inserted string 1
Inserted string 2
Inserted string 3
Inserted string 4
Inserted string 5
Inserted string 6
Inserted string 7
Inserted string 8
Inserted string 9
Inserted string 10
Data for key 1 (string 7) : data for string 7
Data for key 2 (string 6) : data for string 6
Data for key 3 (string 5) : data for string 5
Data for key 4 (string 4) : data for string 4
Data for key 5 (string 10) : data for string 10
Data for key 6 (string 3) : data for string 3
Data for key 7 (string 2) : data for string 2
Data for key 8 (string 1) : data for string 1
Data for key 9 (string 9) : data for string 9
Data for key 10 (string 8) : data for string 8
An unhandled exception occurred at 0x0805B37C :
EAccessViolation : Access violation
$0805B37C

This seems to be a error in gdbm.pp:

Function DatumToString(Key : TDatum) : String;
begin
  SetLength(DatumToString,Key.dsize);
  If key.Dsize>0 then
    Move(key.dptr^,DatumToString[1],key.dsize);
  if key.dptrNil then
    cfree(Key.dptr);
end;
The function is called by function gdbm_nextkey(para1:PGDBM_FILE; Const
Para2 :string):string;

I'd changed the DatumToString() function to

Function DatumToString(Key : TDatum) : String;
begin
  if key.dptr  Nil then
  begin
    SetLength(DatumToString,Key.dsize);
    If key.Dsize>0 then
    Move(key.dptr^,DatumToString[1],key.dsize);
  { if key.dptrNil then }
    cfree(Key.dptr);
  end;
end;

This now works (but due to a lack of experience with this unit it may be wrong)

Anyone here who has the same error with testgdbm2.pp?

I will test next time I have my PC back the same on FreeBSD 5.x.

tia, Christian

Jérémie LEFRANCOIS
to Christian Müllerke

I am not too sure, be I might suggest that instead of moving that test : *** if key.dptrNil then ***
before the line :
*** SetLength(DatumToString,Key.dsize); ***
you could move it *after* that line.

Because I understand that in case key.dptr is nil Move(key.dptr^,... is a mistake, but the setlength(... instruction might be better off if left as is. Removing it might have some bad side effect...

Hope that helps.
Regards.

En réponse à Christian Müllerke :

Show quoted text 74 lines
Hi! Maybe I'd found a bug in gdbm.pp I'm running Linux (2.6.7) and fpc-1.9.4: fpctest2 $ ./testgdbm2 Inserted string 1 Inserted string 2 Inserted string 3 Inserted string 4 Inserted string 5 Inserted string 6 Inserted string 7 Inserted string 8 Inserted string 9 Inserted string 10 Data for key 1 (string 7) : data for string 7 Data for key 2 (string 6) : data for string 6 Data for key 3 (string 5) : data for string 5 Data for key 4 (string 4) : data for string 4 Data for key 5 (string 10) : data for string 10 Data for key 6 (string 3) : data for string 3 Data for key 7 (string 2) : data for string 2 Data for key 8 (string 1) : data for string 1 Data for key 9 (string 9) : data for string 9 Data for key 10 (string 8) : data for string 8 An unhandled exception occurred at 0x0805B37C : EAccessViolation : Access violation $0805B37C This seems to be a error in gdbm.pp: Function DatumToString(Key : TDatum) : String; begin SetLength(DatumToString,Key.dsize); If key.Dsize>0 then Move(key.dptr^,DatumToString[1],key.dsize); if key.dptrNil then cfree(Key.dptr); end; The function is called by function gdbm_nextkey(para1:PGDBM_FILE; Const Para2 :string):string; I'd changed the DatumToString() function to Function DatumToString(Key : TDatum) : String; begin if key.dptr Nil then begin SetLength(DatumToString,Key.dsize); If key.Dsize>0 then Move(key.dptr^,DatumToString[1],key.dsize); { if key.dptrNil then } cfree(Key.dptr); end; end; This now works (but due to a lack of experience with this unit it may be wrong) Anyone here who has the same error with testgdbm2.pp? I will test next time I have my PC back the same on FreeBSD 5.x. tia, Christian _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

__________________
Jérémie Lefrançois
06 73 27 35 97
Consultant
Altran Technologies