Don't walk off front of string when stripping newline

If the string was zero-length to begin with, or consists of only newline
characters, nothing stopped us from incrementing right off the front of
the string. Ensure len stays above zero the whole time.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-08-09 02:34:11 -05:00
parent a42e52a09f
commit 96c4b1c303
1 changed files with 1 additions and 1 deletions

View File

@ -219,7 +219,7 @@ size_t _alpm_strip_newline(char *str)
return 0;
}
len = strlen(str);
while(str[len - 1] == '\n') {
while(len > 0 && str[len - 1] == '\n') {
len--;
}
str[len] = '\0';