Merge pull request #3294 from datauwu/bsdtar-fix-signed-overflow
(cherry picked from commit 10a7247810)
This commit is contained in:
1 parent
c0dcda10c0
commit
148a9f90c1
4 files changed
+19
-40
No files matched your search
@@ -196,7 +196,6 @@ int need_report(void);
|
||||
int pathcmp(const char *a, const char *b);
|
||||
void safe_fprintf(FILE * ARCHIVE_RESTRICT, const char * ARCHIVE_RESTRICT fmt, ...) __LA_PRINTF(2, 3);
|
||||
void set_chdir(struct bsdtar *, const char *newdir);
|
||||
const char *tar_i64toa(int64_t);
|
||||
void tar_mode_c(struct bsdtar *bsdtar);
|
||||
void tar_mode_r(struct bsdtar *bsdtar);
|
||||
void tar_mode_t(struct bsdtar *bsdtar);
|
||||
|
||||
+6
-6
@@ -121,16 +121,16 @@ progress_func(void *cookie)
|
||||
else
|
||||
compression = (int)((uncomp - comp) * 100 / uncomp);
|
||||
fprintf(stderr,
|
||||
"In: %s bytes, compression %d%%;",
|
||||
tar_i64toa(comp), compression);
|
||||
fprintf(stderr, " Out: %d files, %s bytes\n",
|
||||
archive_file_count(a), tar_i64toa(uncomp));
|
||||
"In: %ju bytes, compression %d%%;",
|
||||
(uintmax_t)comp, compression);
|
||||
fprintf(stderr, " Out: %d files, %ju bytes\n",
|
||||
archive_file_count(a), (uintmax_t)uncomp);
|
||||
}
|
||||
if (entry != NULL) {
|
||||
safe_fprintf(stderr, "Current: %s",
|
||||
archive_entry_pathname(entry));
|
||||
fprintf(stderr, " (%s bytes)\n",
|
||||
tar_i64toa(archive_entry_size(entry)));
|
||||
fprintf(stderr, " (%jd bytes)\n",
|
||||
(intmax_t)archive_entry_size(entry));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-22
@@ -584,27 +584,6 @@ edit_mtime(struct bsdtar *bsdtar, struct archive_entry *entry)
|
||||
archive_entry_set_mtime(entry, bsdtar->mtime, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* It would be nice to just use printf() for formatting large numbers,
|
||||
* but the compatibility problems are quite a headache. Hence the
|
||||
* following simple utility function.
|
||||
*/
|
||||
const char *
|
||||
tar_i64toa(int64_t n0)
|
||||
{
|
||||
static char buff[24];
|
||||
uint64_t n = n0 < 0 ? -n0 : n0;
|
||||
char *p = buff + sizeof(buff);
|
||||
|
||||
*--p = '\0';
|
||||
do {
|
||||
*--p = '0' + (int)(n % 10);
|
||||
} while (n /= 10);
|
||||
if (n0 < 0)
|
||||
*--p = '-';
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Like strcmp(), but try to be a little more aware of the fact that
|
||||
* we're comparing two paths. Right now, it just handles leading
|
||||
@@ -748,7 +727,9 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
|
||||
(unsigned long)archive_entry_rdevminor(entry));
|
||||
p = tmp;
|
||||
} else {
|
||||
p = tar_i64toa(archive_entry_size(entry));
|
||||
snprintf(tmp, sizeof(tmp), "%jd",
|
||||
(intmax_t)archive_entry_size(entry));
|
||||
p = tmp;
|
||||
}
|
||||
if (w + strlen(p) >= bsdtar->gs_width)
|
||||
bsdtar->gs_width = w + strlen(p) + 1;
|
||||
|
||||
+10
-11
@@ -598,8 +598,8 @@ cleanup:
|
||||
bsdtar->diskreader = NULL;
|
||||
|
||||
if (bsdtar->flags & OPTFLAG_TOTALS) {
|
||||
fprintf(stderr, "Total bytes written: %s\n",
|
||||
tar_i64toa(archive_filter_bytes(a, -1)));
|
||||
fprintf(stderr, "Total bytes written: %jd\n",
|
||||
(intmax_t)archive_filter_bytes(a, -1));
|
||||
}
|
||||
|
||||
archive_write_free(a);
|
||||
@@ -1043,21 +1043,20 @@ report_write(struct bsdtar *bsdtar, struct archive *a,
|
||||
fprintf(stderr, "\n");
|
||||
comp = archive_filter_bytes(a, -1);
|
||||
uncomp = archive_filter_bytes(a, 0);
|
||||
fprintf(stderr, "In: %d files, %s bytes;",
|
||||
archive_file_count(a), tar_i64toa(uncomp));
|
||||
fprintf(stderr, "In: %d files, %ju bytes;",
|
||||
archive_file_count(a), (uintmax_t)uncomp);
|
||||
if (comp >= uncomp)
|
||||
compression = 0;
|
||||
else
|
||||
compression = (int)((uncomp - comp) * 100 / uncomp);
|
||||
fprintf(stderr,
|
||||
" Out: %s bytes, compression %d%%\n",
|
||||
tar_i64toa(comp), compression);
|
||||
/* Can't have two calls to tar_i64toa() pending, so split the output. */
|
||||
safe_fprintf(stderr, "Current: %s (%s",
|
||||
" Out: %ju bytes, compression %d%%\n",
|
||||
(uintmax_t)comp, compression);
|
||||
safe_fprintf(stderr, "Current: %s (%jd",
|
||||
archive_entry_pathname(entry),
|
||||
tar_i64toa(progress));
|
||||
fprintf(stderr, "/%s bytes)\n",
|
||||
tar_i64toa(archive_entry_size(entry)));
|
||||
(intmax_t)progress);
|
||||
fprintf(stderr, "/%jd bytes)\n",
|
||||
(intmax_t)archive_entry_size(entry));
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in new issue
Block a user