[PATCH] Use size_t for number of lines in linebuf

From: Jakob Kramer <jakob.kramer_AT_gmx.de>
Date: Sat, 31 Jan 2015 20:57:29 +0100

.nlines and .capacity are used as array indices and
should therefore be of type size_t.
---
 cols.c | 14 ++++++--------
 sort.c |  2 +-
 text.h |  4 ++--
 3 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/cols.c b/cols.c
index f89dfb1..fce4c19 100644
--- a/cols.c
+++ b/cols.c
_AT_@ -11,12 +11,12 @@
 #include "utf.h"
 #include "util.h"
 
-static long chars = 65;
+static size_t chars = 65;
 static int cflag;
 static struct linebuf b = EMPTY_LINEBUF;
 
-static long n_columns;
-static long n_rows;
+static size_t n_columns;
+static size_t n_rows;
 
 static void
 usage(void)
_AT_@ -27,16 +27,14 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
-	long i, l, col;
-	size_t len, bytes;
-	int maxlen = 0;
+	size_t i, l, col, len, bytes, maxlen = 0;
 	struct winsize w;
 	FILE *fp;
 
 	ARGBEGIN {
 	case 'c':
 		cflag = 1;
-		chars = estrtonum(EARGF(usage()), 3, LONG_MAX);
+		chars = estrtonum(EARGF(usage()), 3, MIN(LLONG_MAX, SIZE_MAX));
 		break;
 	default:
 		usage();
_AT_@ -84,7 +82,7 @@ main(int argc, char *argv[])
 			len = utflen(b.lines[l]);
 			fputs(b.lines[l], stdout);
 			if (col < n_columns)
-				printf("%*s", maxlen + 1 - (int)len, "");
+				printf("%*s", (int)(maxlen + 1 - len), "");
 		}
 		fputs("\n", stdout);
 	}
diff --git a/sort.c b/sort.c
index d46a84b..3a92b2e 100644
--- a/sort.c
+++ b/sort.c
_AT_@ -52,7 +52,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
-	long i;
+	size_t i;
 	FILE *fp;
 	struct linebuf linebuf = EMPTY_LINEBUF;
 	int global_flags = 0;
diff --git a/text.h b/text.h
index a8117c9..95d2579 100644
--- a/text.h
+++ b/text.h
_AT_@ -2,8 +2,8 @@
 
 struct linebuf {
 	char **lines;
-	long nlines;
-	long capacity;
+	size_t nlines;
+	size_t capacity;
 };
 #define EMPTY_LINEBUF {NULL, 0, 0,}
 void getlines(FILE *, struct linebuf *);
-- 
1.9.1
--------------090206060004080801030504--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Sat Jan 31 2015 - 21:48:03 CET