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:
parent
e1dce078b2
commit
c5982a3eb5
@ -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. */
|
||||
|
@ -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. */
|
||||
|
@ -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. */
|
||||
|
Loading…
Reference in New Issue
Block a user