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>
This commit is contained in:
Dan McGee 2011-06-28 17:46:04 -05:00
parent 9efd10cd2a
commit b94e8ecd1f
5 changed files with 19 additions and 17 deletions

View file

@ -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 */ /* check newpkg first, so that adding backup files is retroactive */
backup = _alpm_needbackup(entryname, alpm_pkg_get_backup(newpkg)); backup = _alpm_needbackup(entryname, alpm_pkg_get_backup(newpkg));
if(backup) { if(backup) {
/* if we force hash_orig to be non-NULL retroactive backup works */
hash_orig = "";
needbackup = 1; needbackup = 1;
} }
@ -268,11 +270,6 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
needbackup = 1; 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)) */ /* 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); _alpm_log(handle, PM_LOG_DEBUG, "original: %s\n", hash_orig);
if(!oldpkg) { 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 /* looks like we have a local file that has a different hash as the
* file in the package, move it to a .pacorig */ * file in the package, move it to a .pacorig */
char newpath[PATH_MAX]; char newpath[PATH_MAX];
@ -352,9 +349,9 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
} else if(hash_orig) { } else if(hash_orig) {
/* the fun part */ /* 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 */ /* 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", _alpm_log(handle, PM_LOG_DEBUG, "action: installing new file: %s\n",
entryname_orig); entryname_orig);
@ -366,18 +363,18 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
errors++; errors++;
} }
} else { } else {
/* there's no sense in installing the same file twice, install /* no sense in installing the same file twice, install
* ONLY is the original and package hashes differ */ * ONLY if the original and package hashes differ */
_alpm_log(handle, PM_LOG_DEBUG, "action: leaving existing file in place\n"); _alpm_log(handle, PM_LOG_DEBUG, "action: leaving existing file in place\n");
unlink(checkfile); 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 /* originally installed file and new file are the same - this
* implies the case above failed - i.e. the file was changed by a * implies the case above failed - i.e. the file was changed by a
* user */ * user */
_alpm_log(handle, PM_LOG_DEBUG, "action: leaving existing file in place\n"); _alpm_log(handle, PM_LOG_DEBUG, "action: leaving existing file in place\n");
unlink(checkfile); 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 /* this would be magical. The above two cases failed, but the
* user changes just so happened to make the new file exactly the * user changes just so happened to make the new file exactly the
* same as the one in the package... skip it */ * 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_db_t *db = handle->db_local;
alpm_trans_t *trans = handle->trans; alpm_trans_t *trans = handle->trans;
ASSERT(trans != NULL, return -1);
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install", snprintf(scriptlet, PATH_MAX, "%s%s-%s/install",
_alpm_db_path(db), alpm_pkg_get_name(newpkg), _alpm_db_path(db), alpm_pkg_get_name(newpkg),
alpm_pkg_get_version(newpkg)); alpm_pkg_get_version(newpkg));

View file

@ -40,7 +40,7 @@ int _alpm_split_backup(const char *string, alpm_backup_t **backup)
STRDUP(str, string, return -1); STRDUP(str, string, return -1);
/* tab delimiter */ /* tab delimiter */
ptr = strchr(str, '\t'); ptr = str ? strchr(str, '\t') : NULL;
if(ptr == NULL) { if(ptr == NULL) {
(*backup)->name = str; (*backup)->name = str;
(*backup)->hash = NULL; (*backup)->hash = NULL;

View file

@ -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 *_alpm_conflict_dup(const alpm_conflict_t *conflict)
{ {
alpm_conflict_t *newconflict; 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->package1, conflict->package1, return NULL);
STRDUP(newconflict->package2, conflict->package2, return NULL); STRDUP(newconflict->package2, conflict->package2, return NULL);

View file

@ -162,7 +162,7 @@ static int curl_download_internal(alpm_handle_t *handle,
char hostname[256]; char hostname[256];
char error_buffer[CURL_ERROR_SIZE]; char error_buffer[CURL_ERROR_SIZE];
struct stat st; struct stat st;
long timecond, remote_time; long timecond, remote_time = -1;
double remote_size, bytes_dl; double remote_size, bytes_dl;
struct sigaction sig_pipe[2], sig_int[2]; struct sigaction sig_pipe[2], sig_int[2];
struct fileinfo dlfile; struct fileinfo dlfile;

View file

@ -721,15 +721,18 @@ static void cl_to_log(int argc, char* argv[])
{ {
size_t size = 0; size_t size = 0;
int i; int i;
for(i = 0; i<argc; i++) { for(i = 0; i < argc; i++) {
size += strlen(argv[i]) + 1; size += strlen(argv[i]) + 1;
} }
if(!size) {
return;
}
char *cl_text = malloc(size); char *cl_text = malloc(size);
if(!cl_text) { if(!cl_text) {
return; return;
} }
char *p = cl_text; char *p = cl_text;
for(i = 0; i<argc-1; i++) { for(i = 0; i < argc - 1; i++) {
strcpy(p, argv[i]); strcpy(p, argv[i]);
p += strlen(argv[i]); p += strlen(argv[i]);
*p++ = ' '; *p++ = ' ';