[fpc-devel] Valgrind strscan

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Apr 10 15:09:34 CEST 2008


On 10 Apr 2008, at 14:50, petr.kristan at epos.cz wrote:

> ==14379== Invalid read of size 4
> ==14379==    at 0x80708F0: SYSUTILS_STRSCAN$PCHAR$CHAR$$PCHAR  
> (strings.inc:439)
> ==14379==    by 0x804828A: main (str.pas:9)
> ==14379==  Address 0x416A494 is 4 bytes inside a block of size 5  
> alloc'd
> ==14379==    at 0x401D38B: malloc (vg_replace_malloc.c:149)
> ==14379==    by 0x8063398: CMEM_CGETMEM$LONGWORD$$POINTER (cmem.pp:50)
> ==14379==    by 0x805AFA6: SYSTEM_GETMEM$POINTER$LONGWORD (heap.inc: 
> 235)
> ==14379==    by 0x8048276: main (str.pas:7)
>
> Problem is in assembler code for i386. rtl/i386/strings.inc.
> This routine reads always 4 bytes alligned by 4 regardless string  
> length.
>
> function strscan(p : pchar;c : char) : pchar;assembler;
> ...
> // load new 4 bytes
>        movl     (%edi),%edx   <-here valgrind report Invalid read
> ...
>
> Problem was discovered aleady here http://bugs.freepascal.org/view.php?id=6314
>
> My assembler knowledge is unfortunately not so good yet to  
> effectively repair it.
> Besides routine is very sophisticated. :)
> But I think that solving this cosmetic error will save many developers
> hours during valgrind code checking. And preparing testcases fo fpc
> developers.

It is a false positive by Valgrind. That code intentionally does not  
care about reading uninitialised memory from time to time, and treats  
that situation correctly. There is similar code in glibc, but Valgrind  
comes with standard suppression files for glibc which suppress these  
false positives. I'm not aware of any suppression files for FPC.


Jonas



More information about the fpc-devel mailing list