From b94e8ecd1fec4426baab8c90e7fc0d5583acdbef Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 28 Jun 2011 17:46:04 -0500 Subject: Fix a few warnings pointed out via clang scan-build Some of these are legit (the backup hash NULL checks), while others are either extemely unlikely or just impossible for the static code analysis to prove, but are worth adding anyway because they have little overhead. Signed-off-by: Dan McGee --- lib/libalpm/add.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'lib/libalpm/add.c') diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index b8b1ca18..2d4b7baa 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -257,6 +257,8 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, /* check newpkg first, so that adding backup files is retroactive */ backup = _alpm_needbackup(entryname, alpm_pkg_get_backup(newpkg)); if(backup) { + /* if we force hash_orig to be non-NULL retroactive backup works */ + hash_orig = ""; needbackup = 1; } @@ -268,11 +270,6 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, needbackup = 1; } } - - /* if we force hash_orig to be non-NULL retroactive backup works */ - if(needbackup && !hash_orig) { - hash_orig = ""; - } } } /* else if(S_ISLNK(entrymode)) */ @@ -319,7 +316,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, _alpm_log(handle, PM_LOG_DEBUG, "original: %s\n", hash_orig); if(!oldpkg) { - if(strcmp(hash_local, hash_pkg) != 0) { + if(hash_local && hash_pkg && strcmp(hash_local, hash_pkg) != 0) { /* looks like we have a local file that has a different hash as the * file in the package, move it to a .pacorig */ char newpath[PATH_MAX]; @@ -352,9 +349,9 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, } else if(hash_orig) { /* the fun part */ - if(strcmp(hash_orig, hash_local) == 0) { + if(hash_local && strcmp(hash_orig, hash_local) == 0) { /* installed file has NOT been changed by user */ - if(strcmp(hash_orig, hash_pkg) != 0) { + if(hash_pkg && strcmp(hash_orig, hash_pkg) != 0) { _alpm_log(handle, PM_LOG_DEBUG, "action: installing new file: %s\n", entryname_orig); @@ -366,18 +363,18 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive, errors++; } } else { - /* there's no sense in installing the same file twice, install - * ONLY is the original and package hashes differ */ + /* no sense in installing the same file twice, install + * ONLY if the original and package hashes differ */ _alpm_log(handle, PM_LOG_DEBUG, "action: leaving existing file in place\n"); unlink(checkfile); } - } else if(strcmp(hash_orig, hash_pkg) == 0) { + } else if(hash_pkg && strcmp(hash_orig, hash_pkg) == 0) { /* originally installed file and new file are the same - this * implies the case above failed - i.e. the file was changed by a * user */ _alpm_log(handle, PM_LOG_DEBUG, "action: leaving existing file in place\n"); unlink(checkfile); - } else if(strcmp(hash_local, hash_pkg) == 0) { + } else if(hash_local && hash_pkg && strcmp(hash_local, hash_pkg) == 0) { /* this would be magical. The above two cases failed, but the * user changes just so happened to make the new file exactly the * same as the one in the package... skip it */ @@ -460,6 +457,8 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, alpm_db_t *db = handle->db_local; alpm_trans_t *trans = handle->trans; + ASSERT(trans != NULL, return -1); + snprintf(scriptlet, PATH_MAX, "%s%s-%s/install", _alpm_db_path(db), alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg)); -- cgit v1.2.3-24-g4f1b