|
From: Matthew J F. <mfl...@se...> - 2005-08-12 12:16:33
|
On Friday 12 Aug 2005 10:08 am, Josef Weidendorfer wrote:
> On Friday 12 August 2005 10:23, Matthew J Fletcher wrote:
> > ---- test.c ----
> > int main(void)
> > {
> > char *Deflate = strstr( "gzip,deflate", "deflate" );
> > if ( !Deflate )
> > return 0;
> >
> > if ( *(Deflate + 8 ) == ';' )
> > return 1;
> >
> > return 2;
> > }
> > ...
> > ok, the code is clearly wrong and is accessing space past the end of a
> > staticly allocated buffer. For some reason valgrind, is not finding this.
>
> But obviously the space after the staticly allocated buffer is defined and
> valid, so VG has no way to regard this as error.
"gzip,deflate" is a unique symbol to a constant string in the elf, the pointer
Deflate points (after the strstr) to an address 6 bytes into that symbol.
When you add 8 to the address of the Deflate pointer the address reached is
beyond the end of the symbol and will either point into the next constant
string symbol or off the end of the section.
> > if ( *(Deflate + 8 ) == ';' )
> > goto exit;
> > // return 1;
> >
> > exit:
> > free(String);
> > return 0;
> >...
> > oops, no error report this time, valgrind does not like goto's, which i
> > suppose i should take as a hint.
>
> No. It seems that the compiler optimizes away the if. So there is no
> problem in the produced code.
>
> Josef
at -O0 gcc 3.4.x does not do any dead code optimisations.
regards
---
Matthew J Fletcher
Embedded Software
Serck Controls Ltd
---
**********************************************************************
Serck Controls Ltd, Rowley Drive, Coventry, CV3 4FH, UK
Tel: +44 (0) 24 7630 5050 Fax: +44 (0) 24 7630 2437
Web: www.serck-controls.com Admin: po...@se...
A subsidiary of Serck Controls Pty. Ltd. Reg. in England No. 4353634
**********************************************************************
This email and files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the above. Any views or opinions presented are those of the author
and do not necessarily represent those of Serck Controls Ltd.
This message has been checked by MessageLabs
******************************************************************
|