xz: Fix some of the warnings from -Wsign-conversion.

This commit is contained in:
Lasse Collin 2019-06-23 23:19:34 +03:00
parent c2b994fe3d
commit 7883d73530
7 changed files with 14 additions and 13 deletions

View File

@ -218,7 +218,7 @@ parse_real(args_info *args, int argc, char **argv)
// Compression preset (also for decompression if --format=raw)
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
coder_set_preset(c - '0');
coder_set_preset((uint32_t)(c - '0'));
break;
// --memlimit-compress
@ -683,7 +683,7 @@ args_parse(args_info *args, int argc, char **argv)
// We got at least one filename from the command line, or
// --files or --files0 was specified.
args->arg_names = argv + optind;
args->arg_count = argc - optind;
args->arg_count = (unsigned int)(argc - optind);
}
return;

View File

@ -906,7 +906,7 @@ coder_run(const char *filename)
== CODER_INIT_PASSTHRU;
const uint64_t in_size
= pair->src_st.st_size <= 0
? 0 : pair->src_st.st_size;
? 0 : (uint64_t)(pair->src_st.st_size);
message_progress_start(&strm,
is_passthru, in_size);

View File

@ -360,13 +360,14 @@ io_copy_attrs(const file_pair *pair)
// Try changing the owner of the file. If we aren't root or the owner
// isn't already us, fchown() probably doesn't succeed. We warn
// about failing fchown() only if we are root.
if (fchown(pair->dest_fd, pair->src_st.st_uid, -1) && warn_fchown)
if (fchown(pair->dest_fd, pair->src_st.st_uid, (gid_t)(-1))
&& warn_fchown)
message_warning(_("%s: Cannot set the file owner: %s"),
pair->dest_name, strerror(errno));
mode_t mode;
if (fchown(pair->dest_fd, -1, pair->src_st.st_gid)) {
if (fchown(pair->dest_fd, (uid_t)(-1), pair->src_st.st_gid)) {
message_warning(_("%s: Cannot set the file group: %s"),
pair->dest_name, strerror(errno));
// We can still safely copy some additional permissions:

View File

@ -440,8 +440,8 @@ progress_remaining(uint64_t in_pos, uint64_t elapsed)
// Calculate the estimate. Don't give an estimate of zero seconds,
// since it is possible that all the input has been already passed
// to the library, but there is still quite a bit of output pending.
uint32_t remaining = (double)(expected_in_size - in_pos)
* ((double)(elapsed) / 1000.0) / (double)(in_pos);
uint32_t remaining = (uint32_t)((double)(expected_in_size - in_pos)
* ((double)(elapsed) / 1000.0) / (double)(in_pos));
if (remaining < 1)
remaining = 1;

View File

@ -39,11 +39,11 @@ mytime_now(void)
while (clock_gettime(clk_id, &tv))
clk_id = CLOCK_REALTIME;
return (uint64_t)(tv.tv_sec) * UINT64_C(1000) + tv.tv_nsec / 1000000;
return (uint64_t)tv.tv_sec * 1000 + (uint64_t)(tv.tv_nsec / 1000000);
#else
struct timeval tv;
gettimeofday(&tv, NULL);
return (uint64_t)(tv.tv_sec) * UINT64_C(1000) + tv.tv_usec / 1000;
return (uint64_t)tv.tv_sec * 1000 + (uint64_t)(tv.tv_usec / 1000);
#endif
}

View File

@ -258,7 +258,7 @@ set_lzma(void *options, unsigned key, uint64_t value, const char *valuestr)
if (valuestr[0] < '0' || valuestr[0] > '9')
error_lzma_preset(valuestr);
uint32_t preset = valuestr[0] - '0';
uint32_t preset = (uint32_t)(valuestr[0] - '0');
// Currently only "e" is supported as a modifier,
// so keep this simple for now.

View File

@ -79,7 +79,7 @@ str_to_uint64(const char *name, const char *value, uint64_t min, uint64_t max)
result *= 10;
// Another overflow check
const uint32_t add = *value - '0';
const uint32_t add = (uint32_t)(*value - '0');
if (UINT64_MAX - add < result)
goto error;
@ -243,7 +243,7 @@ my_snprintf(char **pos, size_t *left, const char *fmt, ...)
*left = 0;
} else {
*pos += len;
*left -= len;
*left -= (size_t)(len);
}
return;