Prefer signed types in blocking_read etc

* src/compare.c (process_noop, process_rawdata):
Return bool, not int.
* src/compare.c (process_noop, process_rawdata):
* src/create.c (dump_regular_file):
* src/extract.c (extract_file):
* src/misc.c (blocking_read, blocking_write):
* src/sparse.c (sparse_scan_file_raw, sparse_extract_region):
Prefer signed types like idx_t to unsigned ones like size_t.
(sparse_scan_file_raw): Diagnose read errors.
This commit is contained in:
Paul Eggert
2024-08-09 00:22:53 -07:00
parent 88c2aa1616
commit b3992e4ef8
6 changed files with 62 additions and 57 deletions

View File

@@ -216,7 +216,6 @@ sparse_scan_file_raw (struct tar_sparse_file *file)
struct tar_stat_info *st = file->stat_info;
int fd = file->fd;
char buffer[BLOCKSIZE];
size_t count = 0;
off_t offset = 0;
struct sp_array sp = {0, 0};
@@ -225,9 +224,16 @@ sparse_scan_file_raw (struct tar_sparse_file *file)
if (!tar_sparse_scan (file, scan_begin, NULL))
return false;
while ((count = blocking_read (fd, buffer, sizeof buffer)) != 0
&& count != SAFE_READ_ERROR)
while (true)
{
ptrdiff_t count = blocking_read (fd, buffer, sizeof buffer);
if (count <= 0)
{
if (count < 0)
read_diag_details (st->orig_file_name, offset, sizeof buffer);
break;
}
/* Analyze the block. */
if (zero_block_p (buffer, count))
{
@@ -258,7 +264,6 @@ sparse_scan_file_raw (struct tar_sparse_file *file)
sp.offset = offset;
sparse_add_map (st, &sp);
st->archive_file_size += count;
return tar_sparse_scan (file, scan_end, NULL);
}
@@ -489,7 +494,6 @@ sparse_extract_region (struct tar_sparse_file *file, size_t i)
}
else while (write_size > 0)
{
size_t count;
size_t wrbytes = (write_size > BLOCKSIZE) ? BLOCKSIZE : write_size;
union block *blk = find_next_block ();
if (!blk)
@@ -499,7 +503,7 @@ sparse_extract_region (struct tar_sparse_file *file, size_t i)
}
set_next_block_after (blk);
file->dumped_size += BLOCKSIZE;
count = blocking_write (file->fd, blk->buffer, wrbytes);
idx_t count = blocking_write (file->fd, blk->buffer, wrbytes);
write_size -= count;
mv_size_left (file->stat_info->archive_file_size - file->dumped_size);
file->offset += count;