diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-10-15 02:03:06 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-10-15 02:03:06 +0000 |
commit | 4350d70da7a2dc4d69cf80c6e367b0d117bf94b6 (patch) | |
tree | e2f3f523eda2462a250addf22babc05996369e82 /lib/libkvm/kvm_file2.c | |
parent | cd671a3336075a5b02dc4552f4e7bd2bb764f52e (diff) |
Apply reallocarray() idiom.
ok guenther
Diffstat (limited to 'lib/libkvm/kvm_file2.c')
-rw-r--r-- | lib/libkvm/kvm_file2.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/libkvm/kvm_file2.c b/lib/libkvm/kvm_file2.c index 0930a13048a..294b426901f 100644 --- a/lib/libkvm/kvm_file2.c +++ b/lib/libkvm/kvm_file2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_file2.c,v 1.36 2014/07/04 05:58:31 guenther Exp $ */ +/* $OpenBSD: kvm_file2.c,v 1.37 2014/10/15 02:03:05 deraadt Exp $ */ /* * Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com> @@ -227,11 +227,11 @@ kvm_deadfile_byfile(kvm_t *kd, int op, int arg, size_t esize, int *cnt) _kvm_err(kd, kd->program, "can't read nfiles"); return (NULL); } - buflen = nfiles * esize; - where = _kvm_malloc(kd, buflen); + where = _kvm_reallocarray(kd, NULL, nfiles, esize); kd->filebase = (void *)where; if (kd->filebase == NULL) return (NULL); + buflen = nfiles * esize; for (fp = LIST_FIRST(&filehead); fp != NULL && esize <= buflen; @@ -300,11 +300,11 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) return (NULL); } /* this may be more room than we need but counting is expensive */ - buflen = (nfiles + 10) * esize; - where = _kvm_malloc(kd, buflen); + where = _kvm_reallocarray(kd, NULL, nfiles + 10, esize); kd->filebase = (void *)where; if (kd->filebase == NULL) return (NULL); + buflen = (nfiles + 10) * esize; for (pr = LIST_FIRST(&allprocess); pr != NULL; @@ -358,9 +358,11 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt) filed.fd_ofiles = filed0.fd_dfiles; filed.fd_ofileflags = filed0.fd_dfileflags; } else { - size_t fsize = filed.fd_nfiles * OFILESIZE; - char *tmp = realloc(filebuf, fsize); + size_t fsize; + char *tmp = reallocarray(filebuf, + filed.fd_nfiles, OFILESIZE); + fsize = filed.fd_nfiles * OFILESIZE; if (tmp == NULL) { _kvm_syserr(kd, kd->program, "realloc ofiles"); goto cleanup; |