Hi, cmp -l can return exit status 0 despite reporting differences. Reproduced with diffutils 3.12 and upstream HEAD 3cfe0c69f0e4, with a little help from AI.
Reproducer (run in an empty directory): truncate -s 4096 a cp a b printf X | dd of=b bs=1 conv=notrunc status=none cmp -l -n 4096 a b printf 'cmp status: %s\n' "$?" Actual output: 1 0 130 cmp status: 0 Expected exit status: 1, since the files differ. The problem also occurs without -n. Redirecting cmp’s stdout to /dev/null returns the correct status 1. The regression was introduced by commit 35b74c5708bed35d8580c39a96033f6cbe2f1c89, “cmp: C99 decl style in cmp.c”, first released in 3.11. The 3.10 source does not contain this defect. That commit moved “int differing = 0” inside cmp()’s block-reading loop. After -l reports differences in a full block, the next iteration resets the accumulated result. A subsequent equal block or zero-byte read at EOF or the -n limit then causes a successful return. Moving the declaration back outside the loop preserves earlier differences and corrects the reproducer. The /dev/null optimization takes a separate path that returns failure immediately after finding a difference, explaining why that destination behaves differently. Thanks, Ben
