From 51e6206503f4e208e20bee340a0992c2dbccf1fa Mon Sep 17 00:00:00 2001 From: Ian Darwin Date: Sun, 26 Sep 1999 20:47:29 +0000 Subject: Increase MAXMAGIS again, and change the reallocation - don't need to skimp on memory as much as when this code was written! (Thanks Theo). --- usr.bin/file/apprentice.c | 11 ++++++----- usr.bin/file/file.h | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/usr.bin/file/apprentice.c b/usr.bin/file/apprentice.c index 4906115defb..177992aeb63 100644 --- a/usr.bin/file/apprentice.c +++ b/usr.bin/file/apprentice.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apprentice.c,v 1.7 1998/08/21 04:25:02 deraadt Exp $ */ +/* $OpenBSD: apprentice.c,v 1.8 1999/09/26 20:47:28 ian Exp $ */ /* * apprentice - make one pass through /etc/magic, learning its secrets. @@ -36,7 +36,7 @@ #include "file.h" #ifndef lint -static char *moduleid = "$OpenBSD: apprentice.c,v 1.7 1998/08/21 04:25:02 deraadt Exp $"; +static char *moduleid = "$OpenBSD: apprentice.c,v 1.8 1999/09/26 20:47:28 ian Exp $"; #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -52,6 +52,7 @@ static int parse __P((char *, int *, int)); static void eatsize __P((char **)); static int maxmagic = 0; +static int alloc_incr = 256; static int apprentice_1 __P((char *, int)); @@ -181,11 +182,10 @@ int *ndx, check; struct magic *m; char *t, *s; -#define ALLOC_INCR 20 if (nd+1 >= maxmagic){ struct magic *mtmp; - maxmagic += ALLOC_INCR; + maxmagic += alloc_incr; if ((mtmp = (struct magic *) realloc(magic, sizeof(struct magic) * maxmagic)) == NULL) { @@ -198,7 +198,8 @@ int *ndx, check; exit(1); } magic = mtmp; - memset(&magic[*ndx], 0, sizeof(struct magic) * ALLOC_INCR); + memset(&magic[*ndx], 0, sizeof(struct magic) * alloc_incr); + alloc_incr *= 2; } m = &magic[*ndx]; m->flag = 0; diff --git a/usr.bin/file/file.h b/usr.bin/file/file.h index 66cfee8fdd9..8db21741a18 100644 --- a/usr.bin/file/file.h +++ b/usr.bin/file/file.h @@ -1,4 +1,4 @@ -/* $OpenBSD: file.h,v 1.6 1998/10/13 07:51:51 deraadt Exp $ */ +/* $OpenBSD: file.h,v 1.7 1999/09/26 20:47:28 ian Exp $ */ /* * file.h - definitions for file(1) program @@ -37,7 +37,7 @@ typedef u_int32_t uint32; #ifndef HOWMANY # define HOWMANY 8192 /* how much of the file to look at */ #endif -#define MAXMAGIS 1000 /* max entries in /etc/magic */ +#define MAXMAGIS 5000 /* max entries in /etc/magic */ #define MAXDESC 50 /* max leng of text description */ #define MAXstring 32 /* max leng of "string" types */ -- cgit v1.2.3