[pacman-dev] [PATCH 1/3] fix a few warnings reported by clang

Xavier Chantry shiningxc at gmail.com
Sat Dec 5 17:49:05 EST 2009


- remove unused variables
- some more sanity checks
- safer printf

Signed-off-by: Xavier Chantry <shiningxc at gmail.com>
---
 lib/libalpm/add.c      |    2 ++
 lib/libalpm/be_files.c |    2 +-
 lib/libalpm/conflict.c |    2 +-
 lib/libalpm/package.c  |    3 +--
 src/pacman/callback.c  |    4 +++-
 src/pacman/pacman.c    |    2 +-
 src/pacman/util.c      |    2 +-
 7 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index ebcd6a5..dc565ac 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -483,6 +483,8 @@ static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count,
 
 	ALPM_LOG_FUNC;
 
+	ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -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/be_files.c b/lib/libalpm/be_files.c
index 7fc20b8..f685019 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -140,8 +140,8 @@ static int dirlist_from_fs(const char *syncdbpath, alpm_list_t **dirlist)
 			entry[len+1] = '\0';
 			*dirlist = alpm_list_add(*dirlist, entry);
 		}
+		closedir(dbdir);
 	}
-	closedir(dbdir);
 
 	*dirlist = alpm_list_msort(*dirlist, alpm_list_count(*dirlist), _alpm_str_cmp);
 	return(0);
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index e934c01..85db83b 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -408,7 +408,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
 
 	ALPM_LOG_FUNC;
 
-	if(db == NULL || upgrade == NULL) {
+	if(db == NULL || upgrade == NULL || trans == NULL) {
 		return(NULL);
 	}
 
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 83a2fb8..10220af 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -459,7 +459,6 @@ void SYMEXPORT *alpm_pkg_changelog_open(pmpkg_t *pkg)
 		struct archive *archive = NULL;
 		struct archive_entry *entry;
 		const char *pkgfile = pkg->origin_data.file;
-		int ret = ARCHIVE_OK;
 
 		if((archive = archive_read_new()) == NULL) {
 			RET_ERR(PM_ERR_LIBARCHIVE, NULL);
@@ -473,7 +472,7 @@ void SYMEXPORT *alpm_pkg_changelog_open(pmpkg_t *pkg)
 			RET_ERR(PM_ERR_PKG_OPEN, NULL);
 		}
 
-		while((ret = archive_read_next_header(archive, &entry)) == ARCHIVE_OK) {
+		while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
 			const char *entry_name = archive_entry_pathname(entry);
 
 			if(strcmp(entry_name, ".CHANGELOG") == 0) {
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 858bfdf..15f5423 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -365,6 +365,8 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
 		case PM_TRANS_PROGRESS_CONFLICTS_START:
 			opr = _("checking for file conflicts");
 			break;
+		default:
+			return;
 	}
 
 	/* find # of digits in package counts to scale output */
@@ -504,7 +506,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
 			gettimeofday(&initial_time, NULL);
 			xfered_last = (off_t)0;
 			rate_last = 0.0;
-			timediff = get_update_timediff(1);
+			get_update_timediff(1);
 		}
 	} else if(file_xfered == file_total) {
 		/* compute final values */
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index ff6ef5c..3dccd48 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -217,7 +217,7 @@ static void setarch(const char *arch)
 static void cleanup(int ret) {
 	/* free alpm library resources */
 	if(alpm_release() == -1) {
-		pm_printf(PM_LOG_ERROR, alpm_strerrorlast());
+		pm_printf(PM_LOG_ERROR, "%s\n", alpm_strerrorlast());
 	}
 
 	/* free memory */
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 115b367..d395f3d 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -219,7 +219,7 @@ void indentprint(const char *str, int indent)
 	p = wcstr;
 	cidx = indent;
 
-	if(!p) {
+	if(!p || !len) {
 		return;
 	}
 
-- 
1.6.5.4



More information about the pacman-dev mailing list