Lets say I have code like this:
Code:
inline int Len(char *p_chString){int length = 0;while( *p_chString++ ) ++length; return length;}
void RTrim(char *p_chString)
{
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
char *buf;
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
if(*p_chString == 0 || *p_chString == 0x00) //If String Is Not Blank Or Errored
return;
buf = p_chString;
buf += Len(p_chString) - 1;
while (*buf == ' ' && Len(p_chString) )
*buf-- = '\0';
}
Which trims spaces from the right side of a string. Now if I use it like so it works great:
Code:
char cTemp[10];
strncpy(cTemp," t ",10);
RTrim(cTemp);
Like it should. But lets say a stupid user comes along and tries this:
Where you are not passing a variable. How can I test for that?