Fix extra fread after EOF, non-wires-crossed version.
authorDan Gohman <gohman@apple.com>
Tue, 1 Jun 2010 14:09:29 +0000 (14:09 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 1 Jun 2010 14:09:29 +0000 (14:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@105270 91177308-0d34-0410-b5e6-96231b3b80d8

utils/count/count.c

index a37e1e0b25480f46ccebd655654e67639e82389a..ae96791ae497361dd4059c507ad9e037b1001ba3 100644 (file)
@@ -26,13 +26,15 @@ int main(int argc, char **argv) {
   }
 
   NumLines = 0;
-  while ((NumRead = fread(Buffer, 1, sizeof(Buffer), stdin))) {
+  do {
     unsigned i;
 
+    NumRead = fread(Buffer, 1, sizeof(Buffer), stdin);
+
     for (i = 0; i != NumRead; ++i)
       if (Buffer[i] == '\n')
         ++NumLines;
-  }
+  } while (NumRead == sizeof(Buffer));
     
   if (!feof(stdin)) {
     fprintf(stderr, "%s: error reading stdin\n", argv[0]);