Commit 8d2ed5af authored by Jan Včelák's avatar Jan Včelák 🚀

strstrip: fix for whitespace-only string

parent 743909af
......@@ -142,7 +142,7 @@ char *strstrip(const char *str)
// trailing white-spaces
size_t len = strlen(scan);
while (len > 1 && isspace((int)scan[len - 1])) {
while (len > 0 && isspace((int)scan[len - 1])) {
len -= 1;
}
......@@ -151,7 +151,7 @@ char *strstrip(const char *str)
return NULL;
}
memcpy(trimmed, scan, len + 1);
memcpy(trimmed, scan, len);
trimmed[len] = '\0';
return trimmed;
......
......@@ -41,6 +41,10 @@ static void test_strstrip(void)
c = strstrip("");
is_string("", c, "strstrip: empty string");
free(c);
c = strstrip(" ");
is_string("", c, "strstrip: just whitespaces");
free(c);
}
int main(int argc, char *argv[])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment