[pacman-dev] [PATCH] Use size_t for alpm_list sizes

Allan McRae allan at archlinux.org
Wed Dec 8 02:23:29 EST 2010


On 08/12/10 17:07, Allan McRae wrote:
> There is a lot of swtiching between size_t and int for alpm_list sizes
> in the codebase.   Start converting these to all be size_t by adjusting
> the return type of alpm_list_count and fixing all additional warnings
> given by -Wconversion that are generated by this change.
>
> Signed-off-by: Allan McRae<allan at archlinux.org>
> ---

Snip.  A couple of queries/comments I had:

> --- a/lib/libalpm/alpm.h
> +++ b/lib/libalpm/alpm.h
> @@ -405,7 +405,7 @@ typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
>                                      void *, int *);
>
>   /* Transaction Progress callback */
> -typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, int, int);
> +typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, size_t, size_t);

Should the remaining int  (percentage complete) go to a size_t here too 
for consistency?

<snip>

> --- a/lib/libalpm/be_local.c
> +++ b/lib/libalpm/be_local.c
> @@ -422,7 +422,7 @@ int _alpm_local_db_populate(pmdb_t *db)
>   	}
>
>   	closedir(dbdir);
> -	db->pkgcache = alpm_list_msort(db->pkgcache, count, _alpm_pkg_cmp);
> +	db->pkgcache = alpm_list_msort(db->pkgcache, (size_t)count, _alpm_pkg_cmp);
>   	return(count);
>   }
>
> diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
> index b6c9937..5951f2f 100644
> --- a/lib/libalpm/be_sync.c
> +++ b/lib/libalpm/be_sync.c
> @@ -191,7 +191,7 @@ int _alpm_sync_db_populate(pmdb_t *db)
>   		}
>   	}
>
> -	db->pkgcache = alpm_list_msort(db->pkgcache, count, _alpm_pkg_cmp);
> +	db->pkgcache = alpm_list_msort(db->pkgcache, (size_t)count, _alpm_pkg_cmp);
>   	archive_read_finish(archive);
>
>   	return(count);

I know these are plain "cheating" fixes, and probably create warnings 
about converting from signed to unsigned when some warning flag is used, 
but making the actual variables size_t is not particularly possible 
without bigger changes.

Allan


More information about the pacman-dev mailing list