From 12f209fc0e5c4f700ebb69579aa8a557d532eebb Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Tue, 10 Jun 2003 18:28:36 +0000 Subject: [PATCH] Source cleanups. --- ChangeLog | 6 ++++++ src/apprentice.c | 5 +++-- src/apptype.c | 15 ++++++++------- src/magic.c | 4 +++- src/magic.h | 10 +++++++++- src/softmagic.c | 10 +++++----- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index f69694bd..111f0047 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-06-10 17:03 Christos Zoulas + + * make sure we don't access uninitialized memory. + * pass lint + * #ifdef __cplusplus in magic.h + 2003-05-25 19:23 Christos Zoulas * rename cvs magic file to revision to deal with diff --git a/src/apprentice.c b/src/apprentice.c index ad2774b5..c78c5956 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -50,7 +50,7 @@ #endif #ifndef lint -FILE_RCSID("@(#)$Id: apprentice.c,v 1.58 2003/05/23 21:31:58 christos Exp $") +FILE_RCSID("@(#)$Id: apprentice.c,v 1.59 2003/06/10 18:28:37 christos Exp $") #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -101,6 +101,7 @@ private int apprentice_compile(struct magic_set *, struct magic **, uint32_t *, const char *); private size_t maxmagic = 0; +private size_t magicsize = sizeof(struct magic); #ifdef COMPILE_ONLY const char *magicfile; @@ -143,7 +144,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action, int rv = -1; int mapped; - if (sizeof(*magic) != FILE_MAGICSIZE) { + if (magicsize != FILE_MAGICSIZE) { file_error(ms, "Magic element size %lu != %lu", (unsigned long)sizeof(*magic), (unsigned long)FILE_MAGICSIZE); diff --git a/src/apptype.c b/src/apptype.c index 1b68f390..95a53536 100644 --- a/src/apptype.c +++ b/src/apptype.c @@ -24,10 +24,17 @@ * */ -#ifdef __EMX__ #include #include #include + +#include "file.h" + +#ifndef lint +FILE_RCSID("@(#)$Id: apptype.c,v 1.3 2003/06/10 18:28:37 christos Exp $") +#endif /* lint */ + +#ifdef __EMX__ #include #define INCL_DOSSESMGR #define INCL_DOSERRORS @@ -35,12 +42,6 @@ #include typedef ULONG APPTYPE; -#include "file.h" - -#ifndef lint -FILE_RCSID("@(#)$Id: apptype.c,v 1.2 2003/03/24 14:53:31 christos Exp $") -#endif /* lint */ - protected int file_os2_apptype(struct magic_set *ms, const char *fn, const void *buf, size_t nb) diff --git a/src/magic.c b/src/magic.c index 78142bc6..f88efa30 100644 --- a/src/magic.c +++ b/src/magic.c @@ -64,7 +64,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: magic.c,v 1.7 2003/05/23 21:31:58 christos Exp $") +FILE_RCSID("@(#)$Id: magic.c,v 1.8 2003/06/10 18:28:37 christos Exp $") #endif /* lint */ #ifdef __EMX__ @@ -100,6 +100,7 @@ magic_open(int flags) } ms->flags = flags; ms->haderr = 0; + ms->mlist = NULL; return ms; } @@ -117,6 +118,7 @@ magic_load(struct magic_set *ms, const char *magicfile) ml = file_apprentice(ms, magicfile, 0); if (ml == NULL) return -1; + free_mlist(ms->mlist); ms->mlist = ml; return 0; } diff --git a/src/magic.h b/src/magic.h index 91dcb6a5..c4e09ad9 100644 --- a/src/magic.h +++ b/src/magic.h @@ -40,8 +40,12 @@ #define MAGIC_CONTINUE 0x20 /* Return all matches, not just the first */ #define MAGIC_CHECK 0x40 /* Print warnings to stderr */ -typedef struct magic_set *magic_t; +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct magic_set *magic_t; magic_t magic_open(int); void magic_close(magic_t); @@ -55,4 +59,8 @@ int magic_load(magic_t, const char *); int magic_compile(magic_t, const char *); int magic_check(magic_t, const char *); +#ifdef __cplusplus +}; #endif + +#endif /* _MAGIC_H */ diff --git a/src/softmagic.c b/src/softmagic.c index 110ccd83..c3a03c31 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -44,7 +44,7 @@ #ifndef lint -FILE_RCSID("@(#)$Id: softmagic.c,v 1.59 2003/05/23 21:31:59 christos Exp $") +FILE_RCSID("@(#)$Id: softmagic.c,v 1.60 2003/06/10 18:28:37 christos Exp $") #endif /* lint */ private int match(struct magic_set *, struct magic *, uint32_t, @@ -53,9 +53,9 @@ private int mget(struct magic_set *, union VALUETYPE *, const unsigned char *, struct magic *, size_t); private int mcheck(struct magic_set *, union VALUETYPE *, struct magic *); private int32_t mprint(struct magic_set *, union VALUETYPE *, struct magic *); -private void mdebug(int32_t, const char *, size_t); +private void mdebug(uint32_t, const char *, size_t); private int mconvert(struct magic_set *, union VALUETYPE *, struct magic *); -private int check_mem(struct magic_set *, int); +private int check_mem(struct magic_set *, unsigned int); /* * softmagic - lookup one file in database @@ -226,7 +226,7 @@ done: } private int -check_mem(struct magic_set *ms, int level) +check_mem(struct magic_set *ms, unsigned int level) { size_t len; @@ -594,7 +594,7 @@ mconvert(struct magic_set *ms, union VALUETYPE *p, struct magic *m) private void -mdebug(int32_t offset, const char *str, size_t len) +mdebug(uint32_t offset, const char *str, size_t len) { (void) fprintf(stderr, "mget @%d: ", offset); file_showstr(stderr, str, len); -- 2.40.0