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-14 23:25:46 -07:00
parent 88c2aa1616
commit b3992e4ef8
6 changed files with 62 additions and 57 deletions
+17 -17
View File
@@ -76,20 +76,20 @@ report_difference (struct tar_stat_info *st, const char *fmt, ...)
}
/* Take a buffer returned by read_and_process and do nothing with it. */
static int
process_noop (MAYBE_UNUSED size_t size, MAYBE_UNUSED char *data)
static bool
process_noop (MAYBE_UNUSED idx_t size, MAYBE_UNUSED char *data)
{
return 1;
return true;
}
static int
process_rawdata (size_t bytes, char *buffer)
static bool
process_rawdata (idx_t bytes, char *buffer)
{
size_t status = blocking_read (diff_handle, diff_buffer, bytes);
ptrdiff_t status = blocking_read (diff_handle, diff_buffer, bytes);
if (status != bytes)
{
if (status == SAFE_READ_ERROR)
if (status < 0)
{
read_error (current_stat_info.file_name);
report_difference (&current_stat_info, NULL);
@@ -97,31 +97,31 @@ process_rawdata (size_t bytes, char *buffer)
else
{
report_difference (&current_stat_info,
ngettext ("Could only read %lu of %lu byte",
"Could only read %lu of %lu bytes",
ngettext ("Could read only %td of %td byte",
"Could read only %td of %td bytes",
bytes),
(unsigned long) status, (unsigned long) bytes);
status, bytes);
}
return 0;
return false;
}
if (memcmp (buffer, diff_buffer, bytes))
{
report_difference (&current_stat_info, _("Contents differ"));
return 0;
return false;
}
return 1;
return true;
}
/* Some other routine wants SIZE bytes in the archive. For each chunk
of the archive, call PROCESSOR with the size of the chunk, and the
address of the chunk it can work with. The PROCESSOR should return
nonzero for success. Once it returns error, continue skipping
without calling PROCESSOR anymore. */
address of the chunk it can work with. PROCESSOR should return
true for success. Once it fails, continue skipping without calling
PROCESSOR anymore. */
static void
read_and_process (struct tar_stat_info *st, int (*processor) (size_t, char *))
read_and_process (struct tar_stat_info *st, bool (*processor) (idx_t, char *))
{
union block *data_block;
size_t data_size;