q_shared.c :: Q_CleanStr doesn't clean a string (edit: err)


(Chruker) #1

I was looking for the proper way of solving this: http://www.splashdamage.com/index.php?name=pnPHPbb2&file=viewtopic&p=60174#60174

The code below is wrong :frowning: So just ignore this thread. However I’m still looking for a way to solve that problem.

And stumbled over this:


char *Q_CleanStr( char *string ) {
	char*	d;
	char*	s;
	int		c;

	s = string;
	d = string;
	while ((c = *s) != 0 ) {
		if ( Q_IsColorString( s ) ) {
			s++;
		}		
		else if ( c >= 0x20 && c <= 0x7E ) {
			*d++ = c;
		}
		s++;
	}
	*d = '\0';

	// CHRUKER: It was just returning the source string before
	return d;
}

Originally this function returned the string variable, which is just the source so it actually didn’t do anything.


(digibob) #2

The string is cleaned in place, so returning string is the right thing to do.

Returning d as you have done will return the last character of the string ( which wil always be the NUL character ) and is pretty useless :slight_smile:


(Chruker) #3

D:OH, I see that now :slight_smile: