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:
parent
55f3e632fb
commit
f5525a768b
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user