bad, bad. This was crashing the shell on powerpc boxes, though all other archs
seem to have a much more forgiving malloc implementations. I finally found
this bug using electric-fence on a powerpc box.
-Erik
void trim(char *s)
{
+ int len;
+
/* trim trailing whitespace */
- while (isspace(s[strlen(s)-1]))
- s[strlen(s)-1]='\0';
+ while ( (len=strlen(s)) >= 1 && isspace(s[len-1]))
+ s[len-1]='\0';
/* trim leading whitespace */
- memmove(s, &s[strspn(s, " \n\r\t\v")], strlen(s));
-
+ memmove(s, &s[strspn(s, " \n\r\t\v")], len);
}
/* END CODE */