[pacman-dev] [PATCH 1/2] Return boolean from db_populate

Rikard Falkeborn rikard.falkeborn at gmail.com
Thu Sep 22 18:00:00 UTC 2016


Since the number of packages is not used anywhere, just return a
boolean to avoid the implicit cast from size_t to int in be_local.c.
Use 0 as success to be consistent with db_validate.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn at gmail.com>
---

This patch is made on top of the "Fix Gcc overflow patch". It will
apply to master directly, but the diff doesn't match fully.

As suggested by Andrew after concern of casts from size_t to
int, triggered by the "Fix Gcc overflow patch", change the
"populate" functions to return a flag instead of the number
of packages to avoid implicit casting from size_t to int
in local_db_populate().

The next patch changes the sync_db_populate() function to use
size_t for count in order to not implicitly cast the return
value from alpm_list_count() to int.

 lib/libalpm/be_local.c | 2 +-
 lib/libalpm/be_sync.c  | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 3ef1975..43c6bc9 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -612,7 +612,7 @@ static int local_db_populate(alpm_db_t *db)
 	_alpm_log(db->handle, ALPM_LOG_DEBUG, "added %zu packages to package cache for db '%s'\n",
 			count, db->treename);
 
-	return count;
+	return 0;
 }
 
 /* Note: the return value must be freed by the caller */
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 32a669d..f127ed8 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -454,6 +454,7 @@ static int sync_db_populate(alpm_db_t *db)
 	const char *dbpath;
 	size_t est_count;
 	int count, fd;
+	int ret = 0;
 	struct stat buf;
 	struct archive *archive;
 	struct archive_entry *entry;
@@ -487,7 +488,7 @@ static int sync_db_populate(alpm_db_t *db)
 	db->pkgcache = _alpm_pkghash_create(est_count);
 	if(db->pkgcache == NULL) {
 		db->handle->pm_errno = ALPM_ERR_MEMORY;
-		count = -1;
+		ret = -1;
 		goto cleanup;
 	}
 
@@ -520,7 +521,7 @@ cleanup:
 	if(fd >= 0) {
 		close(fd);
 	}
-	return count;
+	return ret;
 }
 
 /* This function validates %FILENAME%. filename must be between 3 and
-- 
2.10.0


More information about the pacman-dev mailing list