From 08ca2dc6896e36ce8fa614854f07a59e97794d39 Mon Sep 17 00:00:00 2001 From: Gregory Alfonso Date: Tue, 6 Dec 2022 15:30:25 -0800 Subject: [PATCH] [count] Use correct integral type Make the types consistent with each other, and return size_t instead of a long int. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D126121 --- llvm/utils/count/count.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/utils/count/count.c b/llvm/utils/count/count.c index 0aacafe..7149c14 100644 --- a/llvm/utils/count/count.c +++ b/llvm/utils/count/count.c @@ -10,7 +10,7 @@ #include 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 @@ int main(int argc, char **argv) { 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 @@ int main(int argc, char **argv) { NumLines = 0; do { - unsigned i; + size_t i; NumRead = fread(Buffer, 1, sizeof(Buffer), stdin); @@ -41,7 +41,7 @@ int main(int argc, char **argv) { } 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; } -- 2.7.4