-/* $OpenBSD: apprentice.c,v 1.30 2014/01/16 21:45:33 tobias Exp $ */
+/* $OpenBSD: apprentice.c,v 1.31 2014/05/18 17:50:11 espie Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
maxmagic = MAXMAGIS;
if ((marray = calloc(maxmagic, sizeof(*marray))) == NULL) {
- file_oomem(ms, maxmagic * sizeof(*marray));
+ file_oomem2(ms, maxmagic, sizeof(*marray));
return -1;
}
marraycount = 0;
for (i = 0; i < marraycount; i++)
mentrycount += marray[i].cont_count;
- if ((*magicp = malloc(sizeof(**magicp) * mentrycount)) == NULL) {
- file_oomem(ms, sizeof(**magicp) * mentrycount);
+ if ((*magicp = reallocarray(NULL, mentrycount, sizeof(**magicp))) == NULL) {
+ file_oomem2(ms, mentrycount, sizeof(**magicp));
errs++;
goto out;
}
if (me->cont_count == me->max_count) {
struct magic *nm;
size_t cnt = me->max_count + ALLOC_CHUNK;
- if ((nm = realloc(me->mp, sizeof(*nm) * cnt)) == NULL) {
- file_oomem(ms, sizeof(*nm) * cnt);
+ if ((nm = reallocarray(me->mp, cnt, sizeof(*nm)))
+ == NULL) {
+ file_oomem2(ms, cnt, sizeof(*nm));
return -1;
}
me->mp = m = nm;
struct magic_entry *mp;
maxmagic += ALLOC_INCR;
- if ((mp = realloc(*mentryp, sizeof(*mp) * maxmagic)) ==
- NULL) {
- file_oomem(ms, sizeof(*mp) * maxmagic);
+ if ((mp = reallocarray(*mentryp, maxmagic,
+ sizeof(*mp))) == NULL) {
+ file_oomem2(ms, maxmagic, sizeof(*mp));
return -1;
}
(void)memset(&mp[*nmentryp], 0, sizeof(*mp) *
}
me = &(*mentryp)[*nmentryp];
if (me->mp == NULL) {
- if ((m = malloc(sizeof(*m) * ALLOC_CHUNK)) == NULL) {
- file_oomem(ms, sizeof(*m) * ALLOC_CHUNK);
+ if ((m = reallocarray(NULL, ALLOC_CHUNK, sizeof(*m))) == NULL) {
+ file_oomem2(ms, ALLOC_CHUNK, sizeof(*m));
return -1;
}
me->mp = m;
-/* $OpenBSD: ascmagic.c,v 1.11 2009/10/27 23:59:37 deraadt Exp $ */
+/* $OpenBSD: ascmagic.c,v 1.12 2014/05/18 17:50:11 espie Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
while (nbytes > 1 && buf[nbytes - 1] == '\0')
nbytes--;
- if ((nbuf = calloc(1, (nbytes + 1) * sizeof(nbuf[0]))) == NULL)
+ if ((nbuf = calloc((nbytes + 1), sizeof(nbuf[0]))) == NULL)
goto done;
- if ((ubuf = calloc(1, (nbytes + 1) * sizeof(ubuf[0]))) == NULL)
+ if ((ubuf = calloc((nbytes + 1), sizeof(ubuf[0]))) == NULL)
goto done;
/*
-/* $OpenBSD: file.h,v 1.23 2013/04/17 15:01:26 deraadt Exp $ */
+/* $OpenBSD: file.h,v 1.24 2014/05/18 17:50:11 espie Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
*/
/*
* file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.23 2013/04/17 15:01:26 deraadt Exp $
+ * @(#)$Id: file.h,v 1.24 2014/05/18 17:50:11 espie Exp $
*/
#ifndef __file_h__
protected void file_badread(struct magic_set *);
protected void file_badseek(struct magic_set *);
protected void file_oomem(struct magic_set *, size_t);
+protected void file_oomem2(struct magic_set *, size_t, size_t);
protected void file_error(struct magic_set *, int, const char *, ...);
protected void file_magerror(struct magic_set *, const char *, ...);
protected void file_magwarn(struct magic_set *, const char *, ...);
-/* $OpenBSD: funcs.c,v 1.7 2009/10/27 23:59:37 deraadt Exp $ */
+/* $OpenBSD: funcs.c,v 1.8 2014/05/18 17:50:11 espie Exp $ */
/*
* Copyright (c) Christos Zoulas 2003.
* All Rights Reserved.
file_error(ms, errno, "cannot allocate %zu bytes", len);
}
+protected void
+file_oomem2(struct magic_set *ms, size_t len, size_t l2)
+{
+ file_error(ms, errno, "cannot allocate %zu * %zu bytes", len, l2);
+}
protected void
file_badseek(struct magic_set *ms)
{