1
0
mirror of https://github.com/moparisthebest/pacman synced 2025-01-06 03:18:02 -05:00

strtrim: don't move empty string

There were many cases where the string coming in was a blank line, e.g.
"\n\0", length 1. The trim routine starts by trimming leading spaces,
thus trimming everything. We would then proceed to do a memmove of the
NULL byte, which is completely worthless as we can just assign it
instead.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-08-25 17:14:19 -05:00
parent e1dce078b2
commit c5982a3eb5
3 changed files with 18 additions and 3 deletions
lib/libalpm
src
pacman
util

View File

@ -192,7 +192,12 @@ char *_alpm_strtrim(char *str)
pch++;
}
if(pch != str) {
memmove(str, pch, (strlen(pch) + 1));
size_t len = strlen(pch);
if(len) {
memmove(str, pch, len + 1);
} else {
*str = '\0';
}
}
/* check if there wasn't anything but whitespace in the string. */

View File

@ -342,7 +342,12 @@ char *strtrim(char *str)
pch++;
}
if(pch != str) {
memmove(str, pch, (strlen(pch) + 1));
size_t len = strlen(pch);
if(len) {
memmove(str, pch, len + 1);
} else {
*str = '\0';
}
}
/* check if there wasn't anything but whitespace in the string. */

View File

@ -103,7 +103,12 @@ static char *strtrim(char *str)
pch++;
}
if(pch != str) {
memmove(str, pch, (strlen(pch) + 1));
size_t len = strlen(pch);
if(len) {
memmove(str, pch, len + 1);
} else {
*str = '\0';
}
}
/* check if there wasn't anything but whitespace in the string. */