1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

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 7c65ae0f5f
commit 37df03ce52
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) // Compression preset (also for decompression if --format=raw)
case '0': case '1': case '2': case '3': case '4': case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': case '5': case '6': case '7': case '8': case '9':
coder_set_preset(c - '0'); coder_set_preset((uint32_t)(c - '0'));
break; break;
// --memlimit-compress // --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 // We got at least one filename from the command line, or
// --files or --files0 was specified. // --files or --files0 was specified.
args->arg_names = argv + optind; args->arg_names = argv + optind;
args->arg_count = argc - optind; args->arg_count = (unsigned int)(argc - optind);
} }
return; return;

View file

@ -905,8 +905,8 @@ coder_run(const char *filename)
const bool is_passthru = init_ret const bool is_passthru = init_ret
== CODER_INIT_PASSTHRU; == CODER_INIT_PASSTHRU;
const uint64_t in_size const uint64_t in_size
= pair->src_st.st_size <= 0 = pair->src_st.st_size <= 0
? 0 : pair->src_st.st_size; ? 0 : (uint64_t)(pair->src_st.st_size);
message_progress_start(&strm, message_progress_start(&strm,
is_passthru, in_size); 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 // 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 // isn't already us, fchown() probably doesn't succeed. We warn
// about failing fchown() only if we are root. // 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"), message_warning(_("%s: Cannot set the file owner: %s"),
pair->dest_name, strerror(errno)); pair->dest_name, strerror(errno));
mode_t mode; 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"), message_warning(_("%s: Cannot set the file group: %s"),
pair->dest_name, strerror(errno)); pair->dest_name, strerror(errno));
// We can still safely copy some additional permissions: // 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, // Calculate the estimate. Don't give an estimate of zero seconds,
// since it is possible that all the input has been already passed // 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. // to the library, but there is still quite a bit of output pending.
uint32_t remaining = (double)(expected_in_size - in_pos) uint32_t remaining = (uint32_t)((double)(expected_in_size - in_pos)
* ((double)(elapsed) / 1000.0) / (double)(in_pos); * ((double)(elapsed) / 1000.0) / (double)(in_pos));
if (remaining < 1) if (remaining < 1)
remaining = 1; remaining = 1;

View file

@ -39,11 +39,11 @@ mytime_now(void)
while (clock_gettime(clk_id, &tv)) while (clock_gettime(clk_id, &tv))
clk_id = CLOCK_REALTIME; 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 #else
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); 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 #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') if (valuestr[0] < '0' || valuestr[0] > '9')
error_lzma_preset(valuestr); 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, // Currently only "e" is supported as a modifier,
// so keep this simple for now. // 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; result *= 10;
// Another overflow check // Another overflow check
const uint32_t add = *value - '0'; const uint32_t add = (uint32_t)(*value - '0');
if (UINT64_MAX - add < result) if (UINT64_MAX - add < result)
goto error; goto error;
@ -243,7 +243,7 @@ my_snprintf(char **pos, size_t *left, const char *fmt, ...)
*left = 0; *left = 0;
} else { } else {
*pos += len; *pos += len;
*left -= len; *left -= (size_t)(len);
} }
return; return;