Prevent trim() from segfaulting on an empty string

This commit is contained in:
Ian Barwick
2015-03-07 23:45:07 +09:00
parent 66b399b886
commit 5a9b6eea1f

View File

@@ -185,6 +185,10 @@ trim(char *s)
char *s1 = s,
*s2 = &s[strlen(s) - 1];
/* If string is empty, no action needed */
if(s2 < s1)
return s;
/* Trim and delimit right side */
while ((isspace(*s2)) && (s2 >= s1))
--s2;