Prefer < 0 to == -1 where either will do

Also, fix an unlikely read overflow in sys_exec_setmtime_script.
* src/buffer.c (open_compressed_archive):
* src/compare.c (verify_volume):
* src/exclist.c (info_attach_exclist):
* src/misc.c (xfork):
* src/sparse.c (sparse_scan_file_seek):
* src/system.c (sys_wait_for_child, sys_spawn_shell)
(wait_for_grandchild, sys_wait_command, sys_exec_info_script)
(sys_exec_checkpoint_script, sys_exec_setmtime_script):
* src/transform.c (_single_transform_name_to_obstack):
* src/xattrs.c (xattrs__acls_set, xattrs_acls_get)
(xattrs_xattrs_get, xattrs__fd_set, xattrs_selinux_get)
(xattrs_selinux_set):
* tests/checkseekhole.c (check_seek_hole, main):
Simplify failure tests by just looking at return value sign.
* src/system.c (sys_exec_setmtime_script):
Don’t assume ‘read’ result fits in int.
(sys_exec_setmtime_script): Don’t reject 1 second before Epoch.
This commit is contained in:
Paul Eggert
2024-08-04 01:41:43 -07:00
parent 9cb1293628
commit 281e03ec6c
9 changed files with 45 additions and 43 deletions
+3 -3
View File
@@ -59,11 +59,11 @@ check_seek_hole (int fd)
return EX_BAD;
offset = lseek (fd, 0, SEEK_DATA);
if (offset == (off_t)-1)
if (offset < 0)
return EX_FAIL;
offset = lseek (fd, offset, SEEK_HOLE);
if (offset == (off_t)-1 || offset == stat.st_size)
if (offset < 0 || offset == stat.st_size)
return EX_FAIL;
return EX_OK;
@@ -79,7 +79,7 @@ main ()
int rc;
char template[] = "testseekhole-XXXXXX";
int fd = mkstemp (template);
if (fd == -1)
if (fd < 0)
return EX_BAD;
rc = check_seek_hole (fd);
close (fd);