[fpc-devel] According to Valgrind, something is wrong in IndexByte

Jan Ruzicka jan.ruzicka at comcast.net
Sat Aug 13 06:03:01 CEST 2005


On Aug 12, 2005, at 05:04, Micha Nelissen wrote:

> Hi,
>
> In TDbf I use MemScan, which is defined as such: (FPC_DISABLE for 
> testing, normally FPC)
>
> <code>
> {$ifdef FPC_DISABLE}
>
> function MemScan(const Buffer: Pointer; Chr: Byte; Length: Integer): 
> Pointer;
> var
>   I: Integer;
> begin
>   I := System.IndexByte(Buffer, Length, Chr);
>   if I = -1 then
>     Result := nil
>   else
>     Result := Buffer+I;
> end;
>
> {$else}
>
> function MemScan(const Buffer: Pointer; Chr: Byte; Length: Integer): 
> Pointer;
> asm
>         PUSH    EDI
>         MOV     EDI,Buffer
>         MOV     AL, Chr
>         MOV     ECX,Length
>         REPNE   SCASB
>         MOV     EAX,0
>         JNE     @@1
>         MOV     EAX,EDI
>         DEC     EAX
> @@1:    POP     EDI
> end;
>
> {$endif}
> </code>
>
> So you see, it's IndexByte with a tweak. If I'm using the FPC version, 
> implemented using IndexByte Valgrind reports a lot of errors like so:
>
> ==13664== 44439 errors in context 34 of 34:
> ==13664== Conditional jump or move depends on uninitialised value(s)
> ==13664==    at 0x80537C9: 
> SYSTEM_INDEXBYTE$formal$LONGINT$BYTE$$LONGINT (i386.inc:312)
> ==13664==    by 0x81C3B28: 
> DBF_COMMON_MEMSCAN$POINTER$BYTE$LONGINT$$POINTER (dbf_common.pas:433)
> ==13664==    by 0x81E51C2: 
> DBF_MEMO_TMEMOFILE_$__READMEMO$LONGINT$TSTREAM (dbf_memo.pas:278)
> ==13664==    by 0x81C6763: 
> DBF_DBFFILE_TDBFFILE_$__RESTRUCTURETABLE$TDBFFIELDDEFS$BOOLEAN 
> (dbf_dbffile.pas:1303)
> ==13664==    by 0x81AD8B4: DBF_TDBF_$__PACKTABLE (dbf.pas:1521)
>
> But if I use my own version (which I use for delphi and is i386 
> specific), it reports no errors in this location, for 
> Dbf_Common/Dbf_Memo.
>
> i386 IndexByte seems way more complex than my custom MemScan, but 
> maybe that's necessary somehow.
>
> Micha
Have you investigated more into the Valgrind behavior?
The jump (JNE     @@1) is reacting to "REPNE SCASB" and all values seem 
to be defined.
Valgrind may be expecting some numerical operation to set the flags.
"Flags Affected: None; however, the CMPS and SCAS instructions do set 
the status flags in the EFLAGS register."
Intel: "IA-32 Intel Architecture Software Developer’s Manual" 
IA-32-2b.pdf

Jan





More information about the fpc-devel mailing list