[fpc-pascal]Error running gdbmtest2.pp

Jérémie LEFRANCOIS j.lefrancois at altran-tech.net
Fri Jul 30 09:29:39 CEST 2004


I am not too sure, be I might suggest that instead of moving that test :
***   if key.dptr<>Nil 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 <cm at cmuellerke.de>:

> Hi!
> 
> Maybe I'd found a bug in gdbm.pp I'm running Linux (2.6.7) and
> fpc-1.9.4:
> 
> smile at mobil 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.dptr<>Nil 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.dptr<>Nil 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  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> 



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




More information about the fpc-pascal mailing list