fix a regression, cmp-s returns 1 even if files are identical

This commit is contained in:
Than Ngo 2024-07-24 11:59:20 +02:00
commit 112f3556e3
2 changed files with 26 additions and 5 deletions

View file

@ -0,0 +1,19 @@
diff -up diffutils-3.10/src/cmp.c.orig diffutils-3.10/src/cmp.c
--- diffutils-3.10/src/cmp.c.orig 2024-07-23 12:27:16.243455513 +0200
+++ diffutils-3.10/src/cmp.c 2024-07-23 12:31:55.560196269 +0200
@@ -343,12 +343,13 @@ main (int argc, char **argv)
/* If only a return code is needed,
and if both input descriptors are associated with plain files,
+ and if both files are larger than 0 bytes (procfs files are always 0),
conclude that the files differ if they have different sizes
and if more bytes will be compared than are in the smaller file. */
if (comparison_type == type_status
- && 0 <= stat_buf[0].st_size && S_ISREG (stat_buf[0].st_mode)
- && 0 <= stat_buf[1].st_size && S_ISREG (stat_buf[1].st_mode))
+ && 0 < stat_buf[0].st_size && S_ISREG (stat_buf[0].st_mode)
+ && 0 < stat_buf[1].st_size && S_ISREG (stat_buf[1].st_mode))
{
off_t s0 = stat_buf[0].st_size - file_position (0);
off_t s1 = stat_buf[1].st_size - file_position (1);