check dep versions before calling strcmp

Fixes a segfault when trying to remove an assumeinstalled
option without a version.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Andrew Gregory 2015-07-16 19:05:31 -04:00 committed by Allan McRae
parent 2d0e2bf255
commit 1ee2032b7f
1 changed files with 12 additions and 1 deletions

View File

@ -613,10 +613,21 @@ static int assumeinstalled_cmp(const void *d1, const void *d2)
const alpm_depend_t *dep1 = d1;
const alpm_depend_t *dep2 = d2;
if(strcmp(dep1->name, dep2->name) == 0 && strcmp(dep1->version, dep2->version) == 0) {
if(dep1->name_hash != dep2->name_hash
|| strcmp(dep1->name, dep2->name) != 0) {
return -1;
}
if(dep1->version && dep2->version
&& strcmp(dep1->version, dep2->version) == 0) {
return 0;
}
if(dep1->version == NULL && dep2->version == NULL) {
return 0;
}
return -1;
}