[pacman-dev] [PATCH] Signed/unsigned mixup fixup

Dan McGee dan at archlinux.org
Tue Sep 29 23:52:37 EDT 2009


After our recent screwup with size_t and ssize_t in the download code, I
found the `-Wsign-conversion` flag to GCC to see if we were doing anything
else boneheaded. I didn't find anything quite as bad, but we did have some
goofups- most of our public unsigned methods would return -1 on error, which
is a bit odd in an unsigned context.

Signed-off-by: Dan McGee <dan at archlinux.org>
---
 lib/libalpm/add.c        |    4 ++--
 lib/libalpm/alpm.h       |   15 ++++++++-------
 lib/libalpm/alpm_list.c  |    2 +-
 lib/libalpm/alpm_list.h  |    2 +-
 lib/libalpm/backup.c     |    2 +-
 lib/libalpm/be_package.c |    5 ++---
 lib/libalpm/conflict.c   |    2 +-
 lib/libalpm/dload.c      |   10 +++++-----
 lib/libalpm/handle.c     |   15 ++++++++++++---
 lib/libalpm/handle.h     |    4 ++--
 lib/libalpm/package.c    |    8 +++++---
 lib/libalpm/remove.c     |   11 ++++++-----
 lib/libalpm/sync.c       |    4 ++--
 lib/libalpm/trans.c      |    2 +-
 lib/libalpm/util.c       |   13 +++++--------
 src/pacman/callback.c    |   31 ++++++++++++++++++++++---------
 src/pacman/conf.h        |    2 +-
 src/pacman/pacman.c      |    4 ++--
 src/pacman/util.c        |   34 ++++++++++++++++++++--------------
 19 files changed, 99 insertions(+), 71 deletions(-)

diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index c6751a4..4120b14 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -199,7 +199,7 @@ static int extract_single_file(struct archive *archive,
 				/* case 12: existing dir, ignore it */
 				if(lsbuf.st_mode != entrymode) {
 					/* if filesystem perms are different than pkg perms, warn user */
-					int mask = 07777;
+					mode_t mask = 07777;
 					_alpm_log(PM_LOG_WARNING, _("directory permissions differ on %s\n"
 								"filesystem: %o  package: %o\n"), entryname, lsbuf.st_mode & mask,
 							entrymode & mask);
@@ -715,7 +715,7 @@ int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
 		return(0);
 	}
 
-	pkg_count = alpm_list_count(trans->add);
+	pkg_count = (int)alpm_list_count(trans->add);
 	pkg_current = 1;
 
 	/* loop through our package list adding/upgrading one at a time */
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index e9fadca..ae2dc1f 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -128,8 +128,8 @@ int alpm_option_set_logfile(const char *logfile);
 const char *alpm_option_get_lockfile();
 /* no set_lockfile, path is determined from dbpath */
 
-unsigned short alpm_option_get_usesyslog();
-void alpm_option_set_usesyslog(unsigned short usesyslog);
+int alpm_option_get_usesyslog();
+void alpm_option_set_usesyslog(int usesyslog);
 
 alpm_list_t *alpm_option_get_noupgrades();
 void alpm_option_add_noupgrade(const char *pkg);
@@ -154,7 +154,8 @@ int alpm_option_remove_ignoregrp(const char *grp);
 const char *alpm_option_get_arch();
 void alpm_option_set_arch(const char *arch);
 
-void alpm_option_set_usedelta(unsigned short usedelta);
+int alpm_option_get_usedelta();
+void alpm_option_set_usedelta(int usedelta);
 
 pmdb_t *alpm_option_get_localdb();
 alpm_list_t *alpm_option_get_syncdbs();
@@ -195,7 +196,7 @@ typedef enum _pmpkgreason_t {
 	PM_PKG_REASON_DEPEND = 1  /* installed as a dependency for another package */
 } pmpkgreason_t;
 
-int alpm_pkg_load(const char *filename, unsigned short full, pmpkg_t **pkg);
+int alpm_pkg_load(const char *filename, int full, pmpkg_t **pkg);
 int alpm_pkg_free(pmpkg_t *pkg);
 int alpm_pkg_checkmd5sum(pmpkg_t *pkg);
 char *alpm_fetch_pkgurl(const char *url);
@@ -231,8 +232,8 @@ size_t alpm_pkg_changelog_read(void *ptr, size_t size,
 		const pmpkg_t *pkg, const void *fp);
 /*int alpm_pkg_changelog_feof(const pmpkg_t *pkg, void *fp);*/
 int alpm_pkg_changelog_close(const pmpkg_t *pkg, void *fp);
-unsigned short alpm_pkg_has_scriptlet(pmpkg_t *pkg);
-unsigned short alpm_pkg_has_force(pmpkg_t *pkg);
+int alpm_pkg_has_scriptlet(pmpkg_t *pkg);
+int alpm_pkg_has_force(pmpkg_t *pkg);
 
 off_t alpm_pkg_download_size(pmpkg_t *newpkg);
 
@@ -395,7 +396,7 @@ typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
 /* Transaction Progress callback */
 typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, int, int);
 
-unsigned int alpm_trans_get_flags();
+int alpm_trans_get_flags();
 alpm_list_t * alpm_trans_get_add();
 alpm_list_t * alpm_trans_get_remove();
 int alpm_trans_init(pmtransflag_t flags,
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index 8b2c7b3..392faa7 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -573,7 +573,7 @@ void SYMEXPORT *alpm_list_getdata(const alpm_list_t *node)
  *
  * @return the number of list items
  */
-int SYMEXPORT alpm_list_count(const alpm_list_t *list)
+unsigned int SYMEXPORT alpm_list_count(const alpm_list_t *list)
 {
 	unsigned int i = 0;
 	const alpm_list_t *lp = list;
diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h
index f079ecf..66cc7d9 100644
--- a/lib/libalpm/alpm_list.h
+++ b/lib/libalpm/alpm_list.h
@@ -73,7 +73,7 @@ alpm_list_t *alpm_list_last(const alpm_list_t *list);
 void *alpm_list_getdata(const alpm_list_t *entry);
 
 /* misc */
-int alpm_list_count(const alpm_list_t *list);
+unsigned int alpm_list_count(const alpm_list_t *list);
 void *alpm_list_find(const alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn);
 void *alpm_list_find_ptr(const alpm_list_t *haystack, const void *needle);
 char *alpm_list_find_str(const alpm_list_t *haystack, const char *needle);
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index e628131..ab02d90 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -33,7 +33,7 @@
 #include "util.h"
 
 /* split a backup string "file\thash" into two strings : file and hash */
-int _alpm_backup_split(const char *string, char **file, char **hash)
+static int _alpm_backup_split(const char *string, char **file, char **hash)
 {
 	char *str = strdup(string);
 	char *ptr;
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 9c7c161..745e17f 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -239,7 +239,7 @@ static pmpkg_t *pkg_load(const char *pkgfile, unsigned short full)
 	if(full) {
 		/* "checking for conflicts" requires a sorted list, ensure that here */
 		_alpm_log(PM_LOG_DEBUG, "sorting package filelist for %s\n", pkgfile);
-		newpkg->files = alpm_list_msort(newpkg->files, alpm_list_count(newpkg->files),
+		newpkg->files = alpm_list_msort(newpkg->files, (int)alpm_list_count(newpkg->files),
 				_alpm_str_cmp);
 		newpkg->infolevel = INFRQ_ALL;
 	} else {
@@ -269,8 +269,7 @@ error:
  * @param pkg address of the package pointer
  * @return 0 on success, -1 on error (pm_errno is set accordingly)
  */
-int SYMEXPORT alpm_pkg_load(const char *filename, unsigned short full,
-		pmpkg_t **pkg)
+int SYMEXPORT alpm_pkg_load(const char *filename, int full, pmpkg_t **pkg)
 {
 	ALPM_LOG_FUNC;
 
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index e934c01..418409e 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -403,7 +403,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
 		alpm_list_t *upgrade, alpm_list_t *remove)
 {
 	alpm_list_t *i, *j, *conflicts = NULL;
-	int numtargs = alpm_list_count(upgrade);
+	int numtargs = (int)alpm_list_count(upgrade);
 	int current;
 
 	ALPM_LOG_FUNC;
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 8b3226b..7538e59 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -59,7 +59,7 @@ static char *get_filename(const char *url) {
 static char *get_destfile(const char *path, const char *filename) {
 	char *destfile;
 	/* len = localpath len + filename len + null */
-	int len = strlen(path) + strlen(filename) + 1;
+	size_t len = strlen(path) + strlen(filename) + 1;
 	CALLOC(destfile, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL));
 	snprintf(destfile, len, "%s%s", path, filename);
 
@@ -69,7 +69,7 @@ static char *get_destfile(const char *path, const char *filename) {
 static char *get_tempfile(const char *path, const char *filename) {
 	char *tempfile;
 	/* len = localpath len + filename len + '.part' len + null */
-	int len = strlen(path) + strlen(filename) + 6;
+	size_t len = strlen(path) + strlen(filename) + 6;
 	CALLOC(tempfile, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL));
 	snprintf(tempfile, len, "%s%s.part", path, filename);
 
@@ -92,7 +92,7 @@ static int download_internal(const char *url, const char *localpath,
 	struct url_stat ust;
 	struct stat st;
 	int chk_resume = 0, ret = 0;
-	size_t dl_thisfile = 0;
+	off_t dl_thisfile = 0;
 	ssize_t nread = 0;
 	char *tempfile, *destfile, *filename;
 	struct sigaction new_action, old_action;
@@ -199,7 +199,7 @@ static int download_internal(const char *url, const char *localpath,
 
 	while((nread = fetchIO_read(dlf, buffer, PM_DLBUF_LEN)) > 0) {
 		size_t nwritten = 0;
-		nwritten = fwrite(buffer, 1, nread, localf);
+		nwritten = fwrite(buffer, 1, (size_t)nread, localf);
 		if((nwritten != nread) || ferror(localf)) {
 			_alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
 					destfile, strerror(errno));
@@ -300,7 +300,7 @@ int _alpm_download_single_file(const char *filename,
 	for(i = servers; i; i = i->next) {
 		const char *server = i->data;
 		char *fileurl = NULL;
-		int len;
+		size_t len;
 
 		/* print server + filename into a buffer */
 		len = strlen(server) + strlen(filename) + 2;
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 012d412..5cbf363 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -169,7 +169,7 @@ const char SYMEXPORT *alpm_option_get_lockfile()
 	return handle->lockfile;
 }
 
-unsigned short SYMEXPORT alpm_option_get_usesyslog()
+int SYMEXPORT alpm_option_get_usesyslog()
 {
 	if (handle == NULL) {
 		pm_errno = PM_ERR_HANDLE_NULL;
@@ -223,6 +223,15 @@ const char SYMEXPORT *alpm_option_get_arch()
 	return handle->arch;
 }
 
+int SYMEXPORT alpm_option_get_usedelta()
+{
+	if (handle == NULL) {
+		pm_errno = PM_ERR_HANDLE_NULL;
+		return -1;
+	}
+	return handle->usedelta;
+}
+
 pmdb_t SYMEXPORT *alpm_option_get_localdb()
 {
 	if (handle == NULL) {
@@ -437,7 +446,7 @@ int SYMEXPORT alpm_option_set_logfile(const char *logfile)
 	return(0);
 }
 
-void SYMEXPORT alpm_option_set_usesyslog(unsigned short usesyslog)
+void SYMEXPORT alpm_option_set_usesyslog(int usesyslog)
 {
 	handle->usesyslog = usesyslog;
 }
@@ -536,7 +545,7 @@ void SYMEXPORT alpm_option_set_arch(const char *arch)
 	if(arch) handle->arch = strdup(arch);
 }
 
-void SYMEXPORT alpm_option_set_usedelta(unsigned short usedelta)
+void SYMEXPORT alpm_option_set_usedelta(int usedelta)
 {
 	handle->usedelta = usedelta;
 }
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index a1eb1cd..afb2a1c 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -57,9 +57,9 @@ typedef struct _pmhandle_t {
 	alpm_list_t *ignoregrp;   /* List of groups to ignore */
 
 	/* options */
-	unsigned short usesyslog;    /* Use syslog instead of logfile? */ /* TODO move to frontend */
+	int usesyslog;    /* Use syslog instead of logfile? */ /* TODO move to frontend */
+	int usedelta;     /* Download deltas if possible */
 	char *arch;       /* Architecture of packages we should allow */
-	unsigned short usedelta;     /* Download deltas if possible */
 } pmhandle_t;
 
 /* global handle variable */
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index de17166..a10c829 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -295,7 +295,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_groups(pmpkg_t *pkg)
 	return pkg->groups;
 }
 
-unsigned short SYMEXPORT alpm_pkg_has_force(pmpkg_t *pkg)
+int SYMEXPORT alpm_pkg_has_force(pmpkg_t *pkg)
 {
 	ALPM_LOG_FUNC;
 
@@ -503,7 +503,9 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size,
 	if(pkg->origin == PKG_FROM_CACHE) {
 		ret = fread(ptr, 1, size, (FILE*)fp);
 	} else if(pkg->origin == PKG_FROM_FILE) {
-		ret = archive_read_data((struct archive*)fp, ptr, size);
+		/* TODO: This is not valid; we can lose error codes here.
+		 * For now the cast allows compiling with -Wsign-conversion */
+		ret = (size_t)archive_read_data((struct archive*)fp, ptr, size);
 	}
 	return(ret);
 }
@@ -541,7 +543,7 @@ int SYMEXPORT alpm_pkg_changelog_close(const pmpkg_t *pkg, void *fp)
 	return(ret);
 }
 
-unsigned short SYMEXPORT alpm_pkg_has_scriptlet(pmpkg_t *pkg)
+int SYMEXPORT alpm_pkg_has_scriptlet(pmpkg_t *pkg)
 {
 	ALPM_LOG_FUNC;
 
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index f31fbfb..ddc0987 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -372,13 +372,14 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
 	ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
 	ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
 
-	pkg_count = alpm_list_count(trans->remove);
+	pkg_count = (int)alpm_list_count(trans->remove);
 
 	for(targ = trans->remove; targ; targ = targ->next) {
 		int position = 0;
 		char scriptlet[PATH_MAX];
 		info = (pmpkg_t*)targ->data;
 		const char *pkgname = NULL;
+		int targcount = (int)alpm_list_count(targ);
 
 		if(handle->trans->state == STATE_INTERRUPTED) {
 			return(0);
@@ -410,10 +411,10 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
 				}
 			}
 
-			int filenum = alpm_list_count(files);
+			unsigned int filenum = alpm_list_count(files);
 			double percent = 0.0;
 			alpm_list_t *newfiles;
-			_alpm_log(PM_LOG_DEBUG, "removing %d files\n", filenum);
+			_alpm_log(PM_LOG_DEBUG, "removing %ud files\n", filenum);
 
 			/* iterate through the list backwards, unlinking files */
 			newfiles = alpm_list_reverse(files);
@@ -424,7 +425,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
 				percent = (double)position / (double)filenum;
 				PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name,
 						(double)(percent * 100), pkg_count,
-						(pkg_count - alpm_list_count(targ) + 1));
+						(pkg_count - targcount + 1));
 				position++;
 			}
 			alpm_list_free(newfiles);
@@ -432,7 +433,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
 
 		/* set progress to 100% after we finish unlinking files */
 		PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, pkgname, 100,
-		         pkg_count, (pkg_count - alpm_list_count(targ) + 1));
+		         pkg_count, (pkg_count - targcount + 1));
 
 		/* run the post-remove script if it exists  */
 		if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index a1a6ea7..392d66a 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -691,7 +691,7 @@ static int apply_deltas(pmtrans_t *trans)
 			pmdelta_t *d = dlts->data;
 			char *delta, *from, *to;
 			char command[PATH_MAX];
-			int len = 0;
+			size_t len = 0;
 
 			delta = _alpm_filecache_find(d->delta);
 			/* the initial package might be in a different cachedir */
@@ -788,7 +788,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
 {
 	alpm_list_t *i, *j, *files = NULL;
 	alpm_list_t *deltas = NULL;
-	int replaces = 0;
+	unsigned int replaces = 0;
 	int errors = 0;
 	const char *cachedir = NULL;
 	int ret = -1;
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index c99f596..3ac6af3 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -407,7 +407,7 @@ cleanup:
 	return(retval);
 }
 
-unsigned int SYMEXPORT alpm_trans_get_flags()
+int SYMEXPORT alpm_trans_get_flags()
 {
 	/* Sanity checks */
 	ASSERT(handle != NULL, return(-1));
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index f78d193..9e91658 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -200,8 +200,7 @@ char *_alpm_strtrim(char *str)
 int _alpm_lckmk()
 {
 	int fd;
-	pid_t pid;
-	char *dir, *ptr, *spid = NULL;
+	char *dir, *ptr;
 	const char *file = alpm_option_get_lockfile();
 
 	/* create the dir of the lockfile first */
@@ -216,13 +215,11 @@ int _alpm_lckmk()
 	while((fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000)) == -1
 			&& errno == EINTR);
 	if(fd > 0) {
-		pid = getpid();
-		size_t len = snprintf(spid, 0, "%ld\n", (long)pid) + 1;
-		spid = malloc(len);
-		snprintf(spid, len, "%ld\n", (long)pid);
-		while(write(fd, (void *)spid, len) == -1 && errno == EINTR);
+		FILE *f = fdopen(fd, "w");
+		fprintf(f, "%ld\n", (long)getpid());
+		fflush(f);
 		fsync(fd);
-		free(spid);
+		fclose(f);
 		return(fd);
 	}
 	return(-1);
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 1dd3ffb..551e769 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -90,10 +90,10 @@ static float get_update_timediff(int first_call)
 static void fill_progress(const int bar_percent, const int disp_percent,
 		const int proglen)
 {
-	const unsigned int hashlen = proglen - 8;
-	const unsigned int hash = bar_percent * hashlen / 100;
-	static unsigned int lasthash = 0, mouth = 0;
-	unsigned int i;
+	const int hashlen = proglen - 8;
+	const int hash = bar_percent * hashlen / 100;
+	static int lasthash = 0, mouth = 0;
+	int i;
 
 	if(bar_percent == 0) {
 		lasthash = 0;
@@ -323,7 +323,8 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
 	int tmp, digits, textlen;
 	char *opr = NULL;
 	/* used for wide character width determination and printing */
-	int len, wclen, wcwid, padwid;
+	size_t len;
+	int wclen, wcwid, padwid;
 	wchar_t *wcstr;
 
 	if(config->noprogressbar) {
@@ -396,7 +397,12 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
 	wclen += mbstowcs(wcstr + wclen, " ", len - wclen);
 	wclen += mbstowcs(wcstr + wclen, pkgname, len - wclen);
 #endif
-	wcwid = wcswidth(wcstr, wclen);
+	if(wclen < 0) {
+		/* we're probably screwed, so... */
+		free(wcstr);
+		return;
+	}
+	wcwid = wcswidth(wcstr, (size_t)wclen);
 	padwid = textlen - wcwid;
 	/* if padwid is < 0, we need to trim the string so padwid = 0 */
 	if(padwid < 0) {
@@ -452,7 +458,8 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
 	const int filenamelen = infolen - 27;
 	char *fname, *p;
 	/* used for wide character width determination and printing */
-	int len, wclen, wcwid, padwid;
+	size_t len;
+	int wclen, wcwid, padwid;
 	wchar_t *wcfname;
 
 	int totaldownload;
@@ -508,7 +515,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
 		rate = xfered / (timediff * 1024.0);
 
 		/* round elapsed time to the nearest second */
-		eta_s = (int)(timediff + 0.5);
+		eta_s = (unsigned int)(timediff + 0.5);
 	} else {
 		/* compute current average values */
 		timediff = get_update_timediff(0);
@@ -557,7 +564,13 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
 	len = strlen(filename) + 1;
 	wcfname = calloc(len, sizeof(wchar_t));
 	wclen = mbstowcs(wcfname, fname, len);
-	wcwid = wcswidth(wcfname, wclen);
+	if(wclen < 0) {
+		/* we're probably screwed, so... */
+		free(fname);
+		free(wcfname);
+		return;
+	}
+	wcwid = wcswidth(wcfname, (size_t)wclen);
 	padwid = filenamelen - wcwid;
 	/* if padwid is < 0, we need to trim the string so padwid = 0 */
 	if(padwid < 0) {
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 3c588a7..598657c 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -64,7 +64,7 @@ typedef struct __config_t {
 	unsigned short group;
 	pmtransflag_t flags;
 	unsigned short noask;
-	unsigned int ask;
+	pmtransprog_t ask;
 
 	/* conf file options */
 	unsigned short chomp; /* I Love Candy! */
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index ac51502..5e824f4 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -612,7 +612,7 @@ static char *get_filename(const char *url) {
 static char *get_destfile(const char *path, const char *filename) {
 	char *destfile;
 	/* len = localpath len + filename len + null */
-	int len = strlen(path) + strlen(filename) + 1;
+	size_t len = strlen(path) + strlen(filename) + 1;
 	destfile = calloc(len, sizeof(char));
 	snprintf(destfile, len, "%s%s", path, filename);
 
@@ -622,7 +622,7 @@ static char *get_destfile(const char *path, const char *filename) {
 static char *get_tempfile(const char *path, const char *filename) {
 	char *tempfile;
 	/* len = localpath len + filename len + '.part' len + null */
-	int len = strlen(path) + strlen(filename) + 6;
+	size_t len = strlen(path) + strlen(filename) + 6;
 	tempfile = calloc(len, sizeof(char));
 	snprintf(tempfile, len, "%s%s.part", path, filename);
 
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 353aae3..94e8f4a 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -232,9 +232,9 @@ char *mdirname(const char *path)
  */
 void indentprint(const char *str, int indent)
 {
-	wchar_t *wcstr;
-	const wchar_t *p;
-	int len, cidx, cols;
+	wchar_t *wcstr, *p;
+	size_t len;
+	int cidx, cols;
 
 	if(!str) {
 		return;
@@ -260,7 +260,8 @@ void indentprint(const char *str, int indent)
 
 	while(*p) {
 		if(*p == L' ') {
-			const wchar_t *q, *next;
+			const wchar_t *next;
+			wchar_t *q;
 			p++;
 			if(p == NULL || *p == L' ') continue;
 			next = wcschr(p, L' ');
@@ -271,7 +272,14 @@ void indentprint(const char *str, int indent)
 			len = 0;
 			q = p;
 			while(q < next) {
-				len += wcwidth(*q++);
+				int w = wcwidth(*q);
+				if(w < 0) {
+					/* hmm. this is no good, kill this char */
+					*q = L'?';
+					w = 1;
+				}
+				q++;
+				len += (unsigned)w;
 			}
 			if(len > (cols - cidx - 1)) {
 				/* wrap to a newline and reindent */
@@ -377,7 +385,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
 		q = alpm_list_getdata(i);
 		if(q > p){
 			/* add chars between this occurence and last occurence, if any */
-			strncpy(newp, p, q - p);
+			strncpy(newp, p, (unsigned)(q - p));
 			newp += q - p;
 		}
 		strncpy(newp, replace, replacesz);
@@ -411,7 +419,7 @@ alpm_list_t *strsplit(const char *str, const char splitchar)
 	char *dup = NULL;
 
 	while((str = strchr(str, splitchar))) {
-		dup = strndup(prev, str - prev);
+		dup = strndup(prev, (size_t)(str - prev));
 		if(dup == NULL) {
 			return(NULL);
 		}
@@ -430,9 +438,9 @@ alpm_list_t *strsplit(const char *str, const char splitchar)
 	return(list);
 }
 
-static int string_length(const char *s)
+static size_t string_length(const char *s)
 {
-	int len;
+	size_t len;
 	wchar_t *wcstr;
 
 	if(!s) {
@@ -442,7 +450,7 @@ static int string_length(const char *s)
 	len = strlen(s) + 1;
 	wcstr = calloc(len, sizeof(wchar_t));
 	len = mbstowcs(wcstr, s, len);
-	len = wcswidth(wcstr, len);
+	len = (size_t)wcswidth(wcstr, len);
 	free(wcstr);
 
 	return(len);
@@ -450,16 +458,14 @@ static int string_length(const char *s)
 
 void string_display(const char *title, const char *string)
 {
-	int len = 0;
-
 	if(title) {
-		/* compute the length of title + a space */
-		len = string_length(title) + 1;
 		printf("%s ", title);
 	}
 	if(string == NULL || string[0] == '\0') {
 		printf(_("None"));
 	} else {
+		/* compute the length of title + a space */
+		int len = string_length(title) + 1;
 		indentprint(string, len);
 	}
 	printf("\n");
-- 
1.6.4.4



More information about the pacman-dev mailing list