[pacman-dev] [PATCH 1/2] Return boolean from db_populate
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@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
Making it size_t matches the return value of alpm_list_count() and avoids the implicit cast to int. Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com> --- lib/libalpm/be_sync.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index f127ed8..079db19 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -452,8 +452,8 @@ static size_t estimate_package_count(struct stat *st, struct archive *archive) static int sync_db_populate(alpm_db_t *db) { const char *dbpath; - size_t est_count; - int count, fd; + size_t est_count, count; + int fd; int ret = 0; struct stat buf; struct archive *archive; @@ -510,10 +510,10 @@ static int sync_db_populate(alpm_db_t *db) count = alpm_list_count(db->pkgcache->list); if(count > 0) { db->pkgcache->list = alpm_list_msort(db->pkgcache->list, - (size_t)count, _alpm_pkg_cmp); + count, _alpm_pkg_cmp); } _alpm_log(db->handle, ALPM_LOG_DEBUG, - "added %d packages to package cache for db '%s'\n", + "added %zu packages to package cache for db '%s'\n", count, db->treename); cleanup: -- 2.10.0
participants (1)
-
Rikard Falkeborn