[PATCH] D126121: Remove undefined behavior in count.c test program [NFC]

Alf via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 6 11:43:48 PST 2022


gAlfonso-bit updated this revision to Diff 480568.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126121/new/

https://reviews.llvm.org/D126121

Files:
  llvm/utils/count/count.c


Index: llvm/utils/count/count.c
===================================================================
--- llvm/utils/count/count.c
+++ llvm/utils/count/count.c
@@ -10,7 +10,7 @@
 #include <stdio.h>
 
 int main(int argc, char **argv) {
-  unsigned Count, NumLines, NumRead;
+  size_t Count, NumLines, NumRead;
   char Buffer[4096], *End;
 
   if (argc != 2) {
@@ -18,7 +18,7 @@
     return 2;
   }
 
-  Count = strtol(argv[1], &End, 10);
+  Count = strtoul(argv[1], &End, 10);
   if (*End != '\0' && End != argv[1]) {
     fprintf(stderr, "%s: invalid count argument '%s'\n", argv[0], argv[1]);
     return 2;
@@ -26,7 +26,7 @@
 
   NumLines = 0;
   do {
-    unsigned i;
+    size_t i;
 
     NumRead = fread(Buffer, 1, sizeof(Buffer), stdin);
 
@@ -41,7 +41,7 @@
   }
 
   if (Count != NumLines) {
-    fprintf(stderr, "Expected %d lines, got %d.\n", Count, NumLines);
+    fprintf(stderr, "Expected %zu lines, got %zu.\n", Count, NumLines);
     return 1;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126121.480568.patch
Type: text/x-patch
Size: 963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221206/5059ee94/attachment.bin>


More information about the llvm-commits mailing list