Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-06-28 17:46:04 -0500
committerDan McGee <dan@archlinux.org>2011-06-30 11:51:36 -0500
commitb94e8ecd1fec4426baab8c90e7fc0d5583acdbef (patch)
treef3d4d2800610893956ccad1691509ddf53c7f487
parent9efd10cd2ac9a7654b2c7c94df86bf09ab54f41a (diff)
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 <dan@archlinux.org>
-rw-r--r--lib/libalpm/add.c23
-rw-r--r--lib/libalpm/backup.c2
-rw-r--r--lib/libalpm/conflict.c2
-rw-r--r--lib/libalpm/dload.c2
-rw-r--r--src/pacman/pacman.c7
5 files changed, 19 insertions, 17 deletions
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));
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index 0334042c..becc7be9 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -40,7 +40,7 @@ int _alpm_split_backup(const char *string, alpm_backup_t **backup)
STRDUP(str, string, return -1);
/* tab delimiter */
- ptr = strchr(str, '\t');
+ ptr = str ? strchr(str, '\t') : NULL;
if(ptr == NULL) {
(*backup)->name = str;
(*backup)->hash = NULL;
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index e54c7147..5d9bbf23 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -65,7 +65,7 @@ void _alpm_conflict_free(alpm_conflict_t *conflict)
alpm_conflict_t *_alpm_conflict_dup(const alpm_conflict_t *conflict)
{
alpm_conflict_t *newconflict;
- CALLOC(newconflict, 1, sizeof(alpm_conflict_t), );
+ CALLOC(newconflict, 1, sizeof(alpm_conflict_t), return NULL);
STRDUP(newconflict->package1, conflict->package1, return NULL);
STRDUP(newconflict->package2, conflict->package2, return NULL);
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 73f75144..fd83aac0 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -162,7 +162,7 @@ static int curl_download_internal(alpm_handle_t *handle,
char hostname[256];
char error_buffer[CURL_ERROR_SIZE];
struct stat st;
- long timecond, remote_time;
+ long timecond, remote_time = -1;
double remote_size, bytes_dl;
struct sigaction sig_pipe[2], sig_int[2];
struct fileinfo dlfile;
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 9ed1c612..cd59c8d4 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -721,15 +721,18 @@ static void cl_to_log(int argc, char* argv[])
{
size_t size = 0;
int i;
- for(i = 0; i<argc; i++) {
+ for(i = 0; i < argc; i++) {
size += strlen(argv[i]) + 1;
}
+ if(!size) {
+ return;
+ }
char *cl_text = malloc(size);
if(!cl_text) {
return;
}
char *p = cl_text;
- for(i = 0; i<argc-1; i++) {
+ for(i = 0; i < argc - 1; i++) {
strcpy(p, argv[i]);
p += strlen(argv[i]);
*p++ = ' ';