diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-03-10 19:14:59 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-03-10 19:14:59 +0000 |
commit | 8120f16b08039d6930497ca14ad531d0b15c7217 (patch) | |
tree | f85c4adb28d78ac38668e7cb4bf76c4024bdcbe0 /usr.bin | |
parent | 22a7a9d54374d0fc8c6f089a9e12a22a3a94a350 (diff) |
realloc & size_t police; simplify some pointer arithmetic; ok ray@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/column/column.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/usr.bin/column/column.c b/usr.bin/column/column.c index f97a289eec0..c24cd6de8c6 100644 --- a/usr.bin/column/column.c +++ b/usr.bin/column/column.c @@ -1,4 +1,4 @@ -/* $OpenBSD: column.c,v 1.10 2003/09/26 22:24:09 tedu Exp $ */ +/* $OpenBSD: column.c,v 1.11 2006/03/10 19:14:58 otto Exp $ */ /* $NetBSD: column.c,v 1.4 1995/09/02 05:53:03 jtc Exp $ */ /* @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)column.c 8.4 (Berkeley) 5/4/95"; #endif -static char rcsid[] = "$OpenBSD: column.c,v 1.10 2003/09/26 22:24:09 tedu Exp $"; +static char rcsid[] = "$OpenBSD: column.c,v 1.11 2006/03/10 19:14:58 otto Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -55,7 +55,7 @@ static char rcsid[] = "$OpenBSD: column.c,v 1.10 2003/09/26 22:24:09 tedu Exp $" #include <unistd.h> void c_columnate(void); -void *emalloc(int); +void *emalloc(size_t); void input(FILE *); void maketbl(void); void print(void); @@ -230,8 +230,8 @@ maketbl(void) err(1, NULL); cols = cols2; lens = lens2; - memset((char *)lens + maxcols * sizeof(int), - 0, DEFCOLS * sizeof(int)); + memset(lens + maxcols, 0, + DEFCOLS * sizeof(int)); maxcols += DEFCOLS; } t->list = emalloc(coloff * sizeof(char *)); @@ -257,7 +257,7 @@ maketbl(void) void input(FILE *fp) { - static int maxentry; + static size_t maxentry; int len; char *p, buf[MAXLINELEN]; @@ -277,19 +277,23 @@ input(FILE *fp) if (maxlength < len) maxlength = len; if (entries == maxentry) { - maxentry += DEFNUM; - if (!(list = realloc(list, - (u_int)maxentry * sizeof(char *)))) + char **nlist; + size_t nsize = maxentry + DEFNUM; + + if (!(nlist = realloc(list, nsize * sizeof(char *)))) err(1, NULL); + list = nlist; + maxentry = nsize; } - list[entries++] = strdup(buf); + if (!(list[entries++] = strdup(buf))) + err(1, NULL); } } void * -emalloc(int size) +emalloc(size_t size) { - char *p; + void *p; if (!(p = malloc(size))) err(1, NULL); |