From: Pádraig Brady
Date: Thu, 16 Sep 2021 11:29:12 +0000 (+0100) Subject: digest: ignore empty lines when checking X-Git-Tag: v9.0~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6c57cf19b1e2660da1ceca92fc8837493cd157e;p=thirdparty%2Fcoreutils.git digest: ignore empty lines when checking * src/digest.c (digest_check): Treat empty lines like comments, as commented checksum files very often have empty lines. * tests/misc/md5sum.pl: Adjust accordingly. --- diff --git a/src/digest.c b/src/digest.c index 9ee37a1040..9398a133ec 100644 --- a/src/digest.c +++ b/src/digest.c @@ -1073,6 +1073,11 @@ digest_check (char const *checkfile_name) line_length -= line[line_length - 1] == '\n'; /* Remove any trailing carriage return. */ line_length -= line[line_length - (0 < line_length)] == '\r'; + + /* Ignore empty lines. */ + if (line_length == 0) + continue; + line[line_length] = '\0'; if (! (split_3 (line, line_length, &hex_digest, &binary, &filename) diff --git a/tests/misc/md5sum.pl b/tests/misc/md5sum.pl index 09c2174f55..64b67deb32 100755 --- a/tests/misc/md5sum.pl +++ b/tests/misc/md5sum.pl @@ -53,18 +53,15 @@ my @Tests = {IN=> {'f.md5' => "$degenerate f\r\n"}}, {OUT=>"f: OK\n"}], - # Same as above, but with an added empty line, to provoke --strict. + # Same as above, but with an added empty line, to test --strict. ['ck-strict-1', '--check --strict', {AUX=> {f=> ''}}, {IN=> {'f.md5' => "$degenerate f\n\n"}}, - {OUT=>"f: OK\n"}, - {ERR=>"md5sum: " - . "WARNING: 1 line is improperly formatted\n"}, - {EXIT=> 1}], + {OUT=>"f: OK\n"}], # As above, but with the invalid line first, to ensure that following # lines are processed in spite of the preceding invalid input line. ['ck-strict-2', '--check --strict', {AUX=> {f=> ''}}, - {IN=> {'in.md5' => "\n$degenerate f\n"}}, + {IN=> {'in.md5' => "ERR\n$degenerate f\n"}}, {OUT=>"f: OK\n"}, {ERR=>"md5sum: " . "WARNING: 1 line is improperly formatted\n"},