Skip to content

Commit

Permalink
[count] Use correct integral type
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AtariDreams authored and MaskRay committed Dec 6, 2022
1 parent a459529 commit 08ca2dc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions llvm/utils/count/count.c
Expand Up @@ -10,23 +10,23 @@
#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) {
fprintf(stderr, "usage: %s <expected line count>\n", argv[0]);
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;
}

NumLines = 0;
do {
unsigned i;
size_t i;

NumRead = fread(Buffer, 1, sizeof(Buffer), stdin);

Expand All @@ -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;
}

Expand Down

0 comments on commit 08ca2dc

Please sign in to comment.