diff options
| author | Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com> | 2025-12-06 14:56:33 +0400 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2026-01-18 01:41:19 +0100 |
| commit | 3bfbce8312b93ef76555da77ac4967d30aeec9fa (patch) | |
| tree | 7fc0ba65dac6f0f11734d307520604952486b6a9 /scripts/basic/docproc.c | |
| parent | 26e9afe22d4b486358f7a66dec5e59a0018289b0 (diff) | |
| download | busybox-w32-3bfbce8312b93ef76555da77ac4967d30aeec9fa.tar.gz busybox-w32-3bfbce8312b93ef76555da77ac4967d30aeec9fa.tar.bz2 busybox-w32-3bfbce8312b93ef76555da77ac4967d30aeec9fa.zip | |
cmp: stop skipping bytes if EOF is reached
Currently, if a skip value is larger than the file size, cmp will continue
to loop and call getc() until the skip count is satisfied, even though
EOF has been reached.
For large skip values (e.g., 1 billion), this results in significant
CPU waste and execution time (e.g., 11 seconds on a modern CPU).
This patch checks for EOF inside the skip loop and breaks early.
Test case:
$ touch empty.txt
$ time ./busybox cmp empty.txt empty.txt 1000000000 1000000000
Before:
real 0m10.937s
After:
real 0m0.002s
function old new delta
cmp_main 594 616 +22
Signed-off-by: Giorgi Tchankvetadze <giorgitchankvetadze1997@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'scripts/basic/docproc.c')
0 files changed, 0 insertions, 0 deletions
