Fix some more simple conversion "errors"

None of these warn at the normal "-Wall -Werror" level, but casts do occur
that we are fine with. Make them explicit to silence some warnings when
using "-Wconversion".

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-01-07 21:06:06 -06:00
parent f966f3a834
commit 62f5da3779
13 changed files with 40 additions and 39 deletions

View file

@ -425,8 +425,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
continue; continue;
} }
double percent = (double)current / numtargs; double percent = (double)current / (double)numtargs;
PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", (percent * 100), PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", (int)(percent * 100),
numtargs, current); numtargs, current);
/* CHECK 1: check every target against every target */ /* CHECK 1: check every target against every target */
_alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s\n", _alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s\n",

View file

@ -172,7 +172,7 @@ int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
alpm_list_t *i; alpm_list_t *i;
int found = 0; int found = 0;
char *newurl; char *newurl;
int len = 0; size_t len = 0;
ALPM_LOG_FUNC; ALPM_LOG_FUNC;

View file

@ -350,8 +350,9 @@ int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
/* This is a bit tricker than the old code for performance reasons. To /* This is a bit tricker than the old code for performance reasons. To
* prevent the need to copy and duplicate strings, strncmp only the name * prevent the need to copy and duplicate strings, strncmp only the name
* portion if they are the same length, since there is a version and * portion if they are the same length, since there is a version and
* operator in play here. */ * operator in play here. Cast is to silence sign conversion warning;
size_t namelen = provver - provision; * we know provver >= provision if we are here. */
size_t namelen = (size_t)(provver - provision);
provver += 1; provver += 1;
satisfy = (strlen(dep->name) == namelen satisfy = (strlen(dep->name) == namelen
&& strncmp(provision, dep->name, namelen) == 0 && strncmp(provision, dep->name, namelen) == 0

View file

@ -178,7 +178,7 @@ static int calculate_removed_size(const alpm_list_t *mount_points,
} }
data = mp->data; data = mp->data;
data->blocks_needed -= ceil((double)(st.st_size) / data->blocks_needed -= (long)ceil((double)(st.st_size) /
(double)(data->fsp.f_bsize)); (double)(data->fsp.f_bsize));
data->used = 1; data->used = 1;
} }
@ -229,7 +229,7 @@ static int calculate_installed_size(const alpm_list_t *mount_points,
} }
data = mp->data; data = mp->data;
data->blocks_needed += ceil((double)(archive_entry_size(entry)) / data->blocks_needed += (long)ceil((double)(archive_entry_size(entry)) /
(double)(data->fsp.f_bsize)); (double)(data->fsp.f_bsize));
data->used = 1; data->used = 1;
} }
@ -243,12 +243,12 @@ cleanup:
int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local) int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
{ {
alpm_list_t *mount_points, *i; alpm_list_t *mount_points, *i;
size_t replaces = 0, current = 0; size_t replaces = 0, current = 0, numtargs;
int abort = 0; int abort = 0;
alpm_list_t *targ; alpm_list_t *targ;
pmpkg_t *pkg; pmpkg_t *pkg;
size_t numtargs = alpm_list_count(trans->add);
numtargs = alpm_list_count(trans->add);
mount_points = mount_point_list(); mount_points = mount_point_list();
if(mount_points == NULL) { if(mount_points == NULL) {
_alpm_log(PM_LOG_ERROR, _("could not determine filesystem mount points")); _alpm_log(PM_LOG_ERROR, _("could not determine filesystem mount points"));
@ -259,8 +259,8 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
if(replaces) { if(replaces) {
numtargs += replaces; numtargs += replaces;
for(targ = trans->remove; targ; targ = targ->next, current++) { for(targ = trans->remove; targ; targ = targ->next, current++) {
double percent = (double)current / numtargs; double percent = (double)current / (double)numtargs;
PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (percent * 100), PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (int)(percent * 100),
numtargs, current); numtargs, current);
pkg = targ->data; pkg = targ->data;
@ -269,8 +269,8 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
} }
for(targ = trans->add; targ; targ = targ->next, current++) { for(targ = trans->add; targ; targ = targ->next, current++) {
double percent = (double)current / numtargs; double percent = (double)current / (double)numtargs;
PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (percent * 100), PROGRESS(trans, PM_TRANS_PROGRESS_DISKSPACE_START, "", (int)(percent * 100),
numtargs, current); numtargs, current);
pkg = targ->data; pkg = targ->data;
@ -295,8 +295,8 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
alpm_mountpoint_t *data = i->data; alpm_mountpoint_t *data = i->data;
if(data->used == 1) { if(data->used == 1) {
/* cushion is roughly min(5% capacity, 20MiB) */ /* cushion is roughly min(5% capacity, 20MiB) */
long fivepc = (data->fsp.f_blocks / 20) + 1; long fivepc = ((long)data->fsp.f_blocks / 20) + 1;
long twentymb = (20 * 1024 * 1024 / data->fsp.f_bsize) + 1; long twentymb = (20 * 1024 * 1024 / (long)data->fsp.f_bsize) + 1;
long cushion = fivepc < twentymb ? fivepc : twentymb; long cushion = fivepc < twentymb ? fivepc : twentymb;
_alpm_log(PM_LOG_DEBUG, "partition %s, needed %ld, cushion %ld, free %ld\n", _alpm_log(PM_LOG_DEBUG, "partition %s, needed %ld, cushion %ld, free %ld\n",

View file

@ -247,7 +247,7 @@ static int download_internal(const char *url, const char *localpath,
while((nread = fetchIO_read(dlf, buffer, PM_DLBUF_LEN)) > 0) { while((nread = fetchIO_read(dlf, buffer, PM_DLBUF_LEN)) > 0) {
check_stop(); check_stop();
size_t nwritten = 0; size_t nwritten = 0;
nwritten = fwrite(buffer, 1, nread, localf); nwritten = fwrite(buffer, 1, (size_t)nread, localf);
if((nwritten != (size_t)nread) || ferror(localf)) { if((nwritten != (size_t)nread) || ferror(localf)) {
pm_errno = PM_ERR_RETRIEVE; pm_errno = PM_ERR_RETRIEVE;
_alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"), _alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),

View file

@ -431,7 +431,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
/* update progress bar after each file */ /* update progress bar after each file */
percent = (double)position / (double)filenum; percent = (double)position / (double)filenum;
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name,
(double)(percent * 100), pkg_count, (int)(percent * 100), pkg_count,
(pkg_count - targcount + 1)); (pkg_count - targcount + 1));
position++; position++;
} }

View file

@ -668,7 +668,7 @@ int _alpm_lstat(const char *path, struct stat *buf)
{ {
int ret; int ret;
char *newpath = strdup(path); char *newpath = strdup(path);
int len = strlen(newpath); size_t len = strlen(newpath);
/* strip the trailing slash if one exists */ /* strip the trailing slash if one exists */
if(len != 0 && newpath[len - 1] == '/') { if(len != 0 && newpath[len - 1] == '/') {
@ -815,7 +815,8 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
b->line_size = b->block_size + 1; b->line_size = b->block_size + 1;
b->line_offset = b->line; b->line_offset = b->line;
} else { } else {
size_t needed = (b->line_offset - b->line) + (i - b->block_offset) + 1; size_t needed = (size_t)((b->line_offset - b->line)
+ (i - b->block_offset) + 1);
if(needed > b->max_line_size) { if(needed > b->max_line_size) {
RET_ERR(PM_ERR_MEMORY, -1); RET_ERR(PM_ERR_MEMORY, -1);
} }
@ -832,7 +833,7 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
} }
if(done) { if(done) {
size_t len = i - b->block_offset; size_t len = (size_t)(i - b->block_offset);
memcpy(b->line_offset, b->block_offset, len); memcpy(b->line_offset, b->block_offset, len);
b->line_offset[len] = '\0'; b->line_offset[len] = '\0';
b->block_offset = ++i; b->block_offset = ++i;
@ -840,7 +841,7 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
return(ARCHIVE_OK); return(ARCHIVE_OK);
} else { } else {
/* we've looked through the whole block but no newline, copy it */ /* we've looked through the whole block but no newline, copy it */
size_t len = b->block + b->block_size - b->block_offset; size_t len = (size_t)(b->block + b->block_size - b->block_offset);
memcpy(b->line_offset, b->block_offset, len); memcpy(b->line_offset, b->block_offset, len);
b->line_offset += len; b->line_offset += len;
b->block_offset = i; b->block_offset = i;

View file

@ -242,7 +242,7 @@ void dump_pkg_changelog(pmpkg_t *pkg)
} else { } else {
/* allocate a buffer to get the changelog back in chunks */ /* allocate a buffer to get the changelog back in chunks */
char buf[CLBUF_SIZE]; char buf[CLBUF_SIZE];
int ret = 0; size_t ret = 0;
while((ret = alpm_pkg_changelog_read(buf, CLBUF_SIZE, pkg, fp))) { while((ret = alpm_pkg_changelog_read(buf, CLBUF_SIZE, pkg, fp))) {
if(ret < CLBUF_SIZE) { if(ret < CLBUF_SIZE) {
/* if we hit the end of the file, we need to add a null terminator */ /* if we hit the end of the file, we need to add a null terminator */

View file

@ -461,7 +461,7 @@ static int parsearg_global(int opt)
case OP_ASK: case OP_ASK:
check_optarg(); check_optarg();
config->noask = 1; config->noask = 1;
config->ask = atoi(optarg); config->ask = (unsigned int)atoi(optarg);
break; break;
case OP_CACHEDIR: case OP_CACHEDIR:
check_optarg(); check_optarg();
@ -483,7 +483,7 @@ static int parsearg_global(int opt)
* here, error and warning are set in config_new, though perhaps a * here, error and warning are set in config_new, though perhaps a
* --quiet option will remove these later */ * --quiet option will remove these later */
if(optarg) { if(optarg) {
unsigned short debug = atoi(optarg); unsigned short debug = (unsigned short)atoi(optarg);
switch(debug) { switch(debug) {
case 2: case 2:
config->logmask |= PM_LOG_FUNCTION; /* fall through */ config->logmask |= PM_LOG_FUNCTION; /* fall through */
@ -1356,7 +1356,7 @@ int main(int argc, char *argv[])
if(!isatty(fileno(stdin))) { if(!isatty(fileno(stdin))) {
char line[PATH_MAX]; char line[PATH_MAX];
int i = 0; int i = 0;
while(i < PATH_MAX && (line[i] = fgetc(stdin)) != EOF) { while(i < PATH_MAX && (line[i] = (char)fgetc(stdin)) != EOF) {
if(isspace((unsigned char)line[i])) { if(isspace((unsigned char)line[i])) {
/* avoid adding zero length arg when multiple spaces separate args */ /* avoid adding zero length arg when multiple spaces separate args */
if(i > 0) { if(i > 0) {

View file

@ -406,10 +406,10 @@ static int check(pmpkg_t *pkg)
} }
if(!config->quiet) { if(!config->quiet) {
printf(_n("%s: %d total file, ", "%s: %d total files, ", allfiles), printf(_n("%s: %d total file, ", "%s: %d total files, ",
pkgname, allfiles); (unsigned long)allfiles), pkgname, allfiles);
printf(_n("%d missing file\n", "%d missing files\n", errors), printf(_n("%d missing file\n", "%d missing files\n",
errors); (unsigned long)errors), errors);
} }
return(errors != 0 ? 1 : 0); return(errors != 0 ? 1 : 0);

View file

@ -346,7 +346,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
/* print the package size with the output if ShowSize option set */ /* print the package size with the output if ShowSize option set */
if(!config->quiet && config->showsize) { if(!config->quiet && config->showsize) {
/* Convert byte size to MB */ /* Convert byte size to MB */
double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0); double mbsize = (double)alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
printf(" [%.2f MB]", mbsize); printf(" [%.2f MB]", mbsize);
} }

View file

@ -275,7 +275,7 @@ char *strtoupper(char *str)
char *ptr = str; char *ptr = str;
while(*ptr) { while(*ptr) {
(*ptr) = toupper((unsigned char)*ptr); (*ptr) = (char)toupper((unsigned char)*ptr);
ptr++; ptr++;
} }
return str; return str;
@ -355,7 +355,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
q = alpm_list_getdata(i); q = alpm_list_getdata(i);
if(q > p){ if(q > p){
/* add chars between this occurence and last occurence, if any */ /* add chars between this occurence and last occurence, if any */
strncpy(newp, p, q - p); strncpy(newp, p, (size_t)(q - p));
newp += q - p; newp += q - p;
} }
strncpy(newp, replace, replacesz); strncpy(newp, replace, replacesz);
@ -389,7 +389,7 @@ alpm_list_t *strsplit(const char *str, const char splitchar)
char *dup = NULL; char *dup = NULL;
while((str = strchr(str, splitchar))) { while((str = strchr(str, splitchar))) {
dup = strndup(prev, str - prev); dup = strndup(prev, (size_t)(str - prev));
if(dup == NULL) { if(dup == NULL) {
return(NULL); return(NULL);
} }
@ -528,8 +528,7 @@ void display_targets(const alpm_list_t *pkgs, int install)
/* print the package size with the output if ShowSize option set */ /* print the package size with the output if ShowSize option set */
if(config->showsize) { if(config->showsize) {
double mbsize = 0.0; double mbsize = (double)alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
pm_asprintf(&str, "%s-%s [%.2f MB]", alpm_pkg_get_name(pkg), pm_asprintf(&str, "%s-%s [%.2f MB]", alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg), mbsize); alpm_pkg_get_version(pkg), mbsize);
@ -541,8 +540,8 @@ void display_targets(const alpm_list_t *pkgs, int install)
} }
/* Convert byte sizes to MB */ /* Convert byte sizes to MB */
mbdlsize = dlsize / (1024.0 * 1024.0); mbdlsize = (double)dlsize / (1024.0 * 1024.0);
mbisize = isize / (1024.0 * 1024.0); mbisize = (double)isize / (1024.0 * 1024.0);
if(install) { if(install) {
pm_asprintf(&str, _("Targets (%d):"), alpm_list_count(targets)); pm_asprintf(&str, _("Targets (%d):"), alpm_list_count(targets));
@ -646,7 +645,7 @@ void print_packages(const alpm_list_t *packages)
if(strstr(temp,"%s")) { if(strstr(temp,"%s")) {
char *size; char *size;
double mbsize = 0.0; double mbsize = 0.0;
mbsize = pkg_get_size(pkg) / (1024.0 * 1024.0); mbsize = (double)pkg_get_size(pkg) / (1024.0 * 1024.0);
pm_asprintf(&size, "%.2f", mbsize); pm_asprintf(&size, "%.2f", mbsize);
string = strreplace(temp, "%s", size); string = strreplace(temp, "%s", size);
free(size); free(size);

View file

@ -116,7 +116,7 @@ static int parse_options(int argc, char *argv[])
break; break;
case 'd': case 'd':
/* validate depth */ /* validate depth */
max_depth = strtol(optarg, &endptr, 10); max_depth = (int)strtol(optarg, &endptr, 10);
if(*endptr != '\0') { if(*endptr != '\0') {
fprintf(stderr, "error: invalid depth -- %s\n", optarg); fprintf(stderr, "error: invalid depth -- %s\n", optarg);
return 1; return 1;