Fix trimming spaces writing at index -1 if an empty string is passed

Submitted by:	Gennady Proskurin <gprspb@mail.ru>
This commit is contained in:
bapt 2015-07-15 18:49:15 +00:00
parent 55f3e632fb
commit f5525a768b

View File

@ -87,11 +87,16 @@ static void
trimlr(char **buf)
{
char *walk = *buf;
char *last;
while (isspace(*walk))
walk++;
while (isspace(walk[strlen(walk) -1]))
walk[strlen(walk) -1] = '\0';
if (*walk != '\0') {
last = walk + strlen(walk) - 1;
while (last > walk && isspace(*last))
last--;
*(last+1) = 0;
}
*buf = walk;
}