Jim,
thanks for the very quick review.

Jim Meyering schrieb:
> Guenter Knauf wrote:
>> -  size_t i;
>> +  size_t i = 0;
>>    bool escaped_filename = false;
>>    size_t algo_name_len;
>>
>> -  i = 0;
>>    while (ISWHITE (s[i]))
>>      ++i;
> 
> Instead, please move the declaration "down".
hmm, not sure what you mean here - moving it down is bad since var
declarations in the middle of the code are not allowed, although
accepted by gcc. In this case its no problem, but if a while later
someone adds code before the declaration then it clashes with non-gcc
compilers. What's bad with initializing a var with the declaration?
That's valid for all compilers AFAIK. Anyway, since its not needed I
left this part out from my new patch - was just only a suggestion to
save a line.

> That allows two or more white-space bytes.
> Let's restrict it to just 0 or 1 space (not white-space) byte.
ok.

>> +      if (strncmp (s + j, "(", 1) == 0)
> 
> This would be better as:
> 
>          if (s[j] == '(')
ok.

here's 2nd trial inline (and also attached) which looks even more simple
thanks to your comments:

--- src/md5sum.c.orig   2009-09-01 13:01:16.000000000 +0200
+++ src/md5sum.c        2009-10-03 20:32:28.000000000 +0200
@@ -263,11 +263,13 @@
   algo_name_len = strlen (DIGEST_TYPE_STRING);
   if (strncmp (s + i, DIGEST_TYPE_STRING, algo_name_len) == 0)
     {
-      if (strncmp (s + i + algo_name_len, " (", 2) == 0)
+      if (s[i + algo_name_len] == ' ')
+        ++i;
+      if (s[i + algo_name_len] == '(')
         {
           *binary = 0;
-          return bsd_split_3 (s +      i + algo_name_len + 2,
-                              s_len - (i + algo_name_len + 2),
+          return bsd_split_3 (s +      i + algo_name_len + 1,
+                              s_len - (i + algo_name_len + 1),
                               hex_digest, file_name);
         }
     }

> And a test, please.
I guess you mean something like that (also attached)?

--- tests/misc/md5sum.orig      2009-09-01 13:01:16.000000000 +0200
+++ tests/misc/md5sum   2009-10-03 20:46:44.000000000 +0200
@@ -67,6 +67,16 @@
      ['check-bsd3', '--check', '--status',
                                 {IN=> {'f.md5' => "MD5 (f) =
$degenerate\n"}},
                                 {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
+     ['check-openssl', '--check', {IN=> {'f.sha1' => "SHA1(f)=
$degenerate\n"}},
+                                {AUX=> {f=> ''}},
+                                {ERR=>"md5sum: f.sha1: no properly
formatted "
+                                       . "MD5 checksum lines found\n"},
+                                {EXIT=> 1}],
+     ['check-openssl2', '--check', {IN=> {'f.md5' => "MD5(f)=
$degenerate\n"}},
+                                {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}],
+     ['check-openssl3', '--check', '--status',
+                                {IN=> {'f.md5' => "MD5(f)=
$degenerate\n"}},
+                                {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
      ['bsd-segv', '--check', {IN=> {'z' => "MD5 ("}}, {EXIT=> 1},
       {ERR=> "$prog: z: no properly formatted MD5 checksum lines
found\n"}],

does this work for you? Sorry, but I've not yet figured out how I could
run these tests - a 'make tests' didnt work (therefore wrote above
blindly assumed)- can you please give me a quick hint before I read me
dead? Thanks. Once I know I create patches for the sha*sum tests too.
Also, is it possible to run single tests?

thanks, Günter.


--- src/md5sum.c.orig	2009-09-01 13:01:16.000000000 +0200
+++ src/md5sum.c	2009-10-03 20:32:28.000000000 +0200
@@ -263,11 +263,13 @@
   algo_name_len = strlen (DIGEST_TYPE_STRING);
   if (strncmp (s + i, DIGEST_TYPE_STRING, algo_name_len) == 0)
     {
-      if (strncmp (s + i + algo_name_len, " (", 2) == 0)
+      if (s[i + algo_name_len] == ' ')
+        ++i;
+      if (s[i + algo_name_len] == '(')
         {
           *binary = 0;
-          return bsd_split_3 (s +      i + algo_name_len + 2,
-                              s_len - (i + algo_name_len + 2),
+          return bsd_split_3 (s +      i + algo_name_len + 1,
+                              s_len - (i + algo_name_len + 1),
                               hex_digest, file_name);
         }
     }
--- tests/misc/md5sum.orig	2009-09-01 13:01:16.000000000 +0200
+++ tests/misc/md5sum	2009-10-03 20:46:44.000000000 +0200
@@ -67,6 +67,16 @@
      ['check-bsd3', '--check', '--status',
                                 {IN=> {'f.md5' => "MD5 (f) = $degenerate\n"}},
                                 {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
+     ['check-openssl', '--check', {IN=> {'f.sha1' => "SHA1(f)= $degenerate\n"}},
+                                {AUX=> {f=> ''}},
+                                {ERR=>"md5sum: f.sha1: no properly formatted "
+                                       . "MD5 checksum lines found\n"},
+                                {EXIT=> 1}],
+     ['check-openssl2', '--check', {IN=> {'f.md5' => "MD5(f)= $degenerate\n"}},
+                                {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}],
+     ['check-openssl3', '--check', '--status',
+                                {IN=> {'f.md5' => "MD5(f)= $degenerate\n"}},
+                                {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
      ['bsd-segv', '--check', {IN=> {'z' => "MD5 ("}}, {EXIT=> 1},
       {ERR=> "$prog: z: no properly formatted MD5 checksum lines found\n"}],
 

Reply via email to