]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(split_3): Accept only old format.
authorJim Meyering <jim@meyering.net>
Thu, 20 Jul 1995 21:09:57 +0000 (21:09 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 20 Jul 1995 21:09:57 +0000 (21:09 +0000)
Properly handle file names with leading and trailing white space.

src/md5sum.c

index a8ad6cb7309be01df40ab38b41130ae172269d6a..1d4fa46d3122414f9c1840f7cb3c61570a4e1131 100644 (file)
@@ -146,45 +146,23 @@ split_3 (s, u, binary, w)
       /* The first field has to be the 32-character hexadecimal
         representation of the message digest.  If it not immediately
         followed by a white space it's an error.  */
-      if (!ISWHITE (s[i + 32]))
+      i += 32;
+      if (!ISWHITE (s[i]))
        return 1;
 
-      i += 32;
       s[i++] = '\0';
 
-      /* Now we have to look for two possibilities: the line is in the
-        new format in which case we have the character 'b' or 't' followed
-        by a white space or we have a ' ' or '*' immediately followed by
-        the file name.  */
-      if (ISWHITE (s[i + 1]))
-       {
-         if (s[i] != 'b' && s[i] != 't')
-           return 1;
-         *binary = s[i] == 'b';
-         i += 2;
-       }
-      else
-       {
-         if (s[i] != ' ' && s[i] != '*')
-           return 1;
-         *binary = s[i] == '*';
-         ++i;
-       }
-
-      if (s[i])
-       {
-         *w = &s[i];
-         /* Skip past the third token.  */
-         while (s[i] && !ISWHITE (s[i]))
-           ++i;
-         if (s[i])
-           s[i++] = '\0';
-         /* Allow trailing white space.  */
-         while (ISWHITE (s[i]))
-           ++i;
-         if (!s[i])
-           return 0;
-       }
+      if (s[i] != ' ' && s[i] != '*')
+       return 1;
+      *binary = s[i++] == '*';
+
+      /* When using the old format, all characters between the type
+        indicator and end of line are significant -- that includes
+        leading and trailing white space.  */
+      *w = &s[i];
+      /* So this line is valid as long as there is at least one character
+        for the filename.  */
+      return (**w ? 0 : 1);
     }
   return 1;
 }