Hi,
...
> > Wrong forum but Im a newbie in Linux and this is a Linux
...
> linux-gcc is the correct list for such problems.
Okey... where can I find it?
> I can't see anything wrong in this code, but more info may help. Is
> 'pek' destroyed at the first iteration, or is it destroyed after the
Im not sure when it is destroid. But I do know that if a match is found then
"pek" is preserved.
> first ? Also, this code assumes that tList.Append makes a new copy of
> the object it is appending, is it so?
Actually Append(...) is creating a class (Node) that has a member of type
sDNS (a struct), somthing like this:
typedef struct tagDNS{ .... } sDNS, psDNS;
Append( const sDNS& s )
{
psDNS pHolder; pHolder = new sDNS;
*pHolder = s;
}
And nothing should matter..."pek" should never ever be changed anyway.
Im using g++ not gcc. But arent they the same.
...
> > The code looks something like this:
> >
> > ///////////////////////////////////////
> > //
> > const char *pek;
> > for( loopIP = IPList.GetFirstNode(); loopIP; loopIP =
> loopIP->GetNext())
> > {
> > if( bMajor ) pek =
rchr(
> loopIP->GetHolder().strDNS, '.' );
> > else pek = strchr( loopIP->GetHolder().strDNS, '.' );
> > if( !pek ) pek = " <N/A> ";
> >
> > fprintf( stderr, "1) pek = \"%s\"\n", pek ); // ** Still ok here **
> >
> > for( loopDNS = tList.GetFirstNode(); loopDNS; loopDNS =
> > loopDNS->GetNext())
> > {
> > if( strcmp( pek,
> loopDNS->GetHolder().strDNS ) == 0 ) break;
> > else fprintf( stderr, "2) pek =
> \"%s\"\n", pek ); // ** NOT here **
> > }
> >
> > fprintf( stderr, "3) pek = \"%s\"\n", pek ); // If point 2 was
> executed then
> > pek is fucked up here
> >
> > if( loopDNS ) loopDNS->GetPointer()->iCount +=
> loopIP->GetHolder().iCount;
> > else
> > {
> > sDNS sTemp;
> > if( strlen( pek ) < sizeof( sTemp.strDNS ) - 1)
> > {
> > fprintf( stderr, "4) pek = \"%s\"\n", pek ); // If point 2 was
> executed then
> > pek is still bad
> > strcpy( sTemp.strDNS, pek );
> > sTemp.iCount =
> loopIP->GetHolder().iCount;
> > tList.Append( sTemp );
> > fprintf( stderr, "5) pek = \"%s\"\n", pek ); // Pek is the same
> here as it
> > was at point 1, but the bad data is allready copied to sTemp.strDNS
> > }
> > else fprintf( stderr, "** ERROR **
> Overflow detected." );
> > }
> > }
> >
> > //
> > ///////////////////////////////////////
> >
> > It seems that "pek" is moved by strcmp(...) to point at bogus
> data if the
> > strings are not the same. But after a few commands the compiler
> restores the
> > value. Maybe strcmp(...) does not restore all registers at
> exit. And after a
> > while the compiler desides to restore them instead.
> >
> > Or Im I doing something wrong?
> >
> > // Jarmo
>