#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.99 2006/12/08 20:31:07 christos Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.100 2006/12/11 21:48:49 christos Exp $")
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
if ((ml = malloc(sizeof(*ml))) == NULL) {
file_delmagic(magic, mapped, nmagic);
- file_oomem(ms);
+ file_oomem(ms, sizeof(*ml));
return -1;
}
fn = MAGIC;
if ((fn = mfn = strdup(fn)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, strlen(fn));
return NULL;
}
if ((mlist = malloc(sizeof(*mlist))) == NULL) {
free(mfn);
- file_oomem(ms);
+ file_oomem(ms, sizeof(*mlist));
return NULL;
}
mlist->next = mlist->prev = mlist;
if (*fn == '\0')
break;
if (ms->flags & MAGIC_MIME) {
- if ((afn = malloc(strlen(fn) + sizeof(mime))) == NULL) {
+ size_t len = strlen(fn) + sizeof(mime);
+ if ((afn = malloc(len)) == NULL) {
free(mfn);
free(mlist);
- file_oomem(ms);
+ file_oomem(ms, len);
return NULL;
}
(void)strcpy(afn, fn);
val += 4 * MULT;
break;
+ case FILE_QUAD:
+ case FILE_BEQUAD:
+ case FILE_LEQUAD:
case FILE_QDATE:
case FILE_LEQDATE:
case FILE_BEQDATE:
maxmagic = MAXMAGIS;
if ((marray = calloc(maxmagic, sizeof(*marray))) == NULL) {
(void)fclose(f);
- file_oomem(ms);
+ file_oomem(ms, maxmagic * sizeof(*marray));
return -1;
}
marraycount = 0;
mentrycount += marray[i].cont_count;
if ((*magicp = malloc(sizeof(**magicp) * mentrycount)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, sizeof(**magicp) * mentrycount);
errs++;
goto out;
}
struct magic *nm;
size_t cnt = me->max_count + ALLOC_CHUNK;
if ((nm = realloc(me->mp, sizeof(*nm) * cnt)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, sizeof(*nm) * cnt);
return -1;
}
me->mp = m = nm;
maxmagic += ALLOC_INCR;
if ((mp = realloc(*mentryp, sizeof(*mp) * maxmagic)) ==
NULL) {
- file_oomem(ms);
+ file_oomem(ms, sizeof(*mp) * maxmagic);
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);
+ file_oomem(ms, sizeof(*m) * ALLOC_CHUNK);
return -1;
}
me->mp = m;
#define RET 2
#else
if ((mm = malloc((size_t)st.st_size)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, (size_t)st.st_size);
goto error;
}
if (read(fd, mm, (size_t)st.st_size) != (size_t)st.st_size) {
uint32_t rv;
uint8_t *s = (uint8_t *)(void *)&sv;
uint8_t *d = (uint8_t *)(void *)&rv;
- d[0] = s[7];
- d[1] = s[6];
- d[2] = s[5];
- d[3] = s[4];
- d[4] = s[3];
- d[5] = s[2];
- d[6] = s[1];
- d[7] = s[0];
+ d[0] = s[3];
+ d[1] = s[2];
+ d[2] = s[1];
+ d[3] = s[0];
+ d[4] = s[7];
+ d[5] = s[6];
+ d[6] = s[5];
+ d[7] = s[4];
return rv;
}
*/
/*
* file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.82 2006/12/08 20:31:07 christos Exp $
+ * @(#)$Id: file.h,v 1.83 2006/12/11 21:48:49 christos Exp $
*/
#ifndef __file_h__
protected void file_delmagic(struct magic *, int type, size_t entries);
protected void file_badread(struct magic_set *);
protected void file_badseek(struct magic_set *);
-protected void file_oomem(struct magic_set *);
+protected void file_oomem(struct magic_set *, size_t);
protected void file_error(struct magic_set *, int, const char *, ...);
protected void file_magwarn(struct magic_set *, const char *, ...);
protected void file_mdump(struct magic *);
#endif
#ifndef lint
-FILE_RCSID("@(#)$Id: funcs.c,v 1.22 2006/10/31 19:37:17 christos Exp $")
+FILE_RCSID("@(#)$Id: funcs.c,v 1.23 2006/12/11 21:48:49 christos Exp $")
#endif /* lint */
#ifndef HAVE_VSNPRINTF
if ((len = vsnprintf(ms->o.ptr, ms->o.len, fmt, ap)) >= ms->o.len) {
va_end(ap);
if ((buf = realloc(ms->o.buf, len + 1024)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, len + 1024);
return -1;
}
ms->o.ptr = buf + (ms->o.ptr - ms->o.buf);
protected void
-file_oomem(struct magic_set *ms)
+file_oomem(struct magic_set *ms, size_t len)
{
- file_error(ms, errno, "cannot allocate memory");
+ file_error(ms, errno, "cannot allocate %zu bytes", len);
}
protected void
nsize = ms->o.len * 4 + 1;
if (ms->o.psize < nsize) {
if ((nbuf = realloc(ms->o.pbuf, nsize)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, nsize);
return NULL;
}
ms->o.psize = nsize;
#ifndef lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.86 2006/12/08 20:31:07 christos Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.87 2006/12/11 21:48:49 christos Exp $")
#endif /* lint */
private int match(struct magic_set *, struct magic *, uint32_t,
ms->c.off = (ms->c.off == NULL) ? malloc(len) : realloc(ms->c.off, len);
if (ms->c.off != NULL)
return 0;
- file_oomem(ms);
+ file_oomem(ms, len);
return -1;
}
return 0;
}
if ((p->search.buf = strdup((const char *)s)) == NULL) {
- file_oomem(ms);
+ file_oomem(ms, strlen((const char *)s));
return -1;
}
for (b = p->search.buf; offset &&