0

Something very strange is happening.
I put a breakpoint in VC++ at the line char *arg and string is what it should be. But as soon as I go to the next line, string changes to this: 0x0012f864 ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ I really have no idea why this is happening and I have no clue as to how to figure it out. Please help.

void CConCommandList::ExecuteString( char *string )
{
	char *arg;
	CTokenStream tokens;
	char cmdargv[10][1024];
	int cmdargc = 0;

	tokens.Init( string );

	arg = tokens.GetNextToken( NULL );
	while( cmdargc < 10 && arg )
	{
		cmdargv[cmdargc][0] = 0;

		C_strcpy( &cmdargv[cmdargc][0], arg );

		arg = tokens.GetNextToken( NULL );
		cmdargc++;
	}

	if( cmdargc )
	{
		ConVar *c = cvar->Find( &cmdargv[0][0] );
		if( c )
		{
			if( cmdargc == 2 )
			{
				c->SetString( &cmdargv[1][0] );
				return;
			}
		}
		else
		{
			char *tempargv[10];

			for( int i = 0; i < 10; i++ )
				tempargv[i] = cmdargv[i];
			CallCommand( &cmdargv[0][0], cmdargc, tempargv );
		}
	}
}
2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

My guess is the problem is in CTokenStream, but could be wrong. The problem could also be somewhere before that function is called, such as buffer overruns.

0

This is how it's being called, the filesystem->* functions are the same as
the standard functions, fopen and fgets.

void CConfigFile::LoadConfigFile( char *filename )
{
	int handle;

	filesystem->OpenFile( &handle, filename, "r" );

	if( handle == -1 )
		return;

	while( true )
	{
		char *temp = filesystem->FGets( handle );
		if( !temp )
			break;

		command->ExecuteString( temp ); // <- here
	}
}

This is what's inside CTokenStream.
C_parse is just a string parser that gets the text inside quotes, brackets etc. I've tested it and it seems fine. It's kinda big so I'm not sure if I should post it.

C_Token returns the token passed in C_parse.

char *GetNextToken( char *in )
	{
		m_pString = C_parse( m_pString );
		m_pToken = C_token( );

		if( !m_pToken )
			return NULL;

		if( !in )
		{
			static char ret[1024];
			strcpy( ret, m_pToken );
			return ret;
		}
		
		strcpy( in, m_pToken );
		return m_pToken;
	}
0

I just realised now as I was looking at FGets.

char *CFileSystem::FGets( int handle )
{
	char dummy[1024];
	return fgets( dummy, 1024, handles[handle] );
}

I just changed it to a static char. Thanks for your help.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.