diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2015-04-01 22:24:03 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2015-04-01 22:24:03 +0000 |
commit | 903444a1c2889fcbad75697412e315fde2b2a4d1 (patch) | |
tree | 10d3dfaa579d54c4a6edb05ad3897e0fdf6a6071 /usr.bin/sort | |
parent | d4139dc3fe069790e0ff3ac154dae39591c7a6dc (diff) |
Just use sort_reallocarray() everywhere.
Diffstat (limited to 'usr.bin/sort')
-rw-r--r-- | usr.bin/sort/file.c | 6 | ||||
-rw-r--r-- | usr.bin/sort/mem.c | 13 | ||||
-rw-r--r-- | usr.bin/sort/mem.h | 3 | ||||
-rw-r--r-- | usr.bin/sort/sort.c | 4 |
4 files changed, 7 insertions, 19 deletions
diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c index 71dd40e02ce..b97d5a76ffd 100644 --- a/usr.bin/sort/file.c +++ b/usr.bin/sort/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.12 2015/04/01 21:33:01 millert Exp $ */ +/* $OpenBSD: file.c,v 1.13 2015/04/01 22:24:02 millert Exp $ */ /*- * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> @@ -664,8 +664,8 @@ file_reader_readline(struct file_reader *fr) if (remsz > (READ_CHUNK >> 1)) { search_start = fr->cbsz - fr->strbeg; fr->cbsz += READ_CHUNK; - fr->buffer = sort_realloc(fr->buffer, - fr->cbsz); + fr->buffer = sort_reallocarray(fr->buffer, + 1, fr->cbsz); bsz1 = fread(fr->buffer + fr->bsz, 1, READ_CHUNK, fr->file); if (bsz1 == 0) { diff --git a/usr.bin/sort/mem.c b/usr.bin/sort/mem.c index 17f9af0633a..03416fe0cf3 100644 --- a/usr.bin/sort/mem.c +++ b/usr.bin/sort/mem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mem.c,v 1.4 2015/04/01 20:58:13 millert Exp $ */ +/* $OpenBSD: mem.c,v 1.5 2015/04/01 22:24:02 millert Exp $ */ /*- * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> @@ -70,17 +70,6 @@ sort_free(void *ptr) } /* - * realloc() wrapper. - */ -void * -sort_realloc(void *ptr, size_t size) -{ - if ((ptr = realloc(ptr, size)) == NULL) - err(2, NULL); - return ptr; -} - -/* * reallocarray() wrapper. */ void * diff --git a/usr.bin/sort/mem.h b/usr.bin/sort/mem.h index 48014787511..14627c90904 100644 --- a/usr.bin/sort/mem.h +++ b/usr.bin/sort/mem.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mem.h,v 1.3 2015/03/30 19:57:36 millert Exp $ */ +/* $OpenBSD: mem.h,v 1.4 2015/04/01 22:24:02 millert Exp $ */ /*- * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> @@ -41,7 +41,6 @@ void *sort_calloc(size_t nmemb, size_t size); void *sort_malloc(size_t); void sort_free(void *ptr); -void *sort_realloc(void *, size_t); void *sort_reallocarray(void *, size_t, size_t); char *sort_strdup(const char *); int sort_asprintf(char **, const char *, ...); diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c index 284c680d3e7..184252c9dab 100644 --- a/usr.bin/sort/sort.c +++ b/usr.bin/sort/sort.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sort.c,v 1.66 2015/04/01 21:45:50 millert Exp $ */ +/* $OpenBSD: sort.c,v 1.67 2015/04/01 22:24:02 millert Exp $ */ /*- * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> @@ -1018,7 +1018,7 @@ main(int argc, char *argv[]) if (keys_num == 0) { keys_num = 1; - keys = sort_realloc(keys, sizeof(struct key_specs)); + keys = sort_reallocarray(keys, 1, sizeof(struct key_specs)); memset(&(keys[0]), 0, sizeof(struct key_specs)); keys[0].c1 = 1; keys[0].pos1b = default_sort_mods->bflag; |