Use size_t for number of lines in linebuf
.nlines and .capacity are used as array indices and should therefore be of type size_t.
This commit is contained in:
		
							
								
								
									
										14
									
								
								cols.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								cols.c
									
									
									
									
									
								
							| @@ -11,12 +11,12 @@ | |||||||
| #include "utf.h" | #include "utf.h" | ||||||
| #include "util.h" | #include "util.h" | ||||||
|  |  | ||||||
| static long chars = 65; | static size_t chars = 65; | ||||||
| static int cflag; | static int cflag; | ||||||
| static struct linebuf b = EMPTY_LINEBUF; | static struct linebuf b = EMPTY_LINEBUF; | ||||||
|  |  | ||||||
| static long n_columns; | static size_t n_columns; | ||||||
| static long n_rows; | static size_t n_rows; | ||||||
|  |  | ||||||
| static void | static void | ||||||
| usage(void) | usage(void) | ||||||
| @@ -27,16 +27,14 @@ usage(void) | |||||||
| int | int | ||||||
| main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
| 	long i, l, col; | 	size_t i, l, col, len, bytes, maxlen = 0; | ||||||
| 	size_t len, bytes; |  | ||||||
| 	int maxlen = 0; |  | ||||||
| 	struct winsize w; | 	struct winsize w; | ||||||
| 	FILE *fp; | 	FILE *fp; | ||||||
|  |  | ||||||
| 	ARGBEGIN { | 	ARGBEGIN { | ||||||
| 	case 'c': | 	case 'c': | ||||||
| 		cflag = 1; | 		cflag = 1; | ||||||
| 		chars = estrtonum(EARGF(usage()), 3, LONG_MAX); | 		chars = estrtonum(EARGF(usage()), 3, MIN(LLONG_MAX, SIZE_MAX)); | ||||||
| 		break; | 		break; | ||||||
| 	default: | 	default: | ||||||
| 		usage(); | 		usage(); | ||||||
| @@ -84,7 +82,7 @@ main(int argc, char *argv[]) | |||||||
| 			len = utflen(b.lines[l]); | 			len = utflen(b.lines[l]); | ||||||
| 			fputs(b.lines[l], stdout); | 			fputs(b.lines[l], stdout); | ||||||
| 			if (col < n_columns) | 			if (col < n_columns) | ||||||
| 				printf("%*s", maxlen + 1 - (int)len, ""); | 				printf("%*s", (int)(maxlen + 1 - len), ""); | ||||||
| 		} | 		} | ||||||
| 		fputs("\n", stdout); | 		fputs("\n", stdout); | ||||||
| 	} | 	} | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								sort.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								sort.c
									
									
									
									
									
								
							| @@ -52,7 +52,7 @@ usage(void) | |||||||
| int | int | ||||||
| main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||||
| { | { | ||||||
| 	long i; | 	size_t i; | ||||||
| 	FILE *fp; | 	FILE *fp; | ||||||
| 	struct linebuf linebuf = EMPTY_LINEBUF; | 	struct linebuf linebuf = EMPTY_LINEBUF; | ||||||
| 	int global_flags = 0; | 	int global_flags = 0; | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								text.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								text.h
									
									
									
									
									
								
							| @@ -2,8 +2,8 @@ | |||||||
|  |  | ||||||
| struct linebuf { | struct linebuf { | ||||||
| 	char **lines; | 	char **lines; | ||||||
| 	long nlines; | 	size_t nlines; | ||||||
| 	long capacity; | 	size_t capacity; | ||||||
| }; | }; | ||||||
| #define EMPTY_LINEBUF {NULL, 0, 0,} | #define EMPTY_LINEBUF {NULL, 0, 0,} | ||||||
| void getlines(FILE *, struct linebuf *); | void getlines(FILE *, struct linebuf *); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user