]> granicus.if.org Git - file/commitdiff
Source cleanups.
authorChristos Zoulas <christos@zoulas.com>
Tue, 10 Jun 2003 18:28:36 +0000 (18:28 +0000)
committerChristos Zoulas <christos@zoulas.com>
Tue, 10 Jun 2003 18:28:36 +0000 (18:28 +0000)
ChangeLog
src/apprentice.c
src/apptype.c
src/magic.c
src/magic.h
src/softmagic.c

index f69694bd6010c3a26691b7f313a90e2043561340..111f0047cdbfd712ab198d3be5050c6c30b42c7b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2003-06-10 17:03  Christos Zoulas  <christos@zoulas.com>
+
+       * make sure we don't access uninitialized memory.
+       * pass lint
+       * #ifdef __cplusplus in magic.h
+
 2003-05-25 19:23  Christos Zoulas  <christos@zoulas.com>
 
        * rename cvs magic file to revision to deal with
index ad2774b5cc8add38f7dabb755761d568a2145412..c78c5956c65a4d0e563ed0fa90fdb165dd5c0d7e 100644 (file)
@@ -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);
index 1b68f390ea255f898eac34a565d3db875e47c5b5..95a535367cef6b9ba405e7ab5041108e46e9d710 100644 (file)
  * 
  */
 
-#ifdef __EMX__
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
+#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 <io.h>
 #define INCL_DOSSESMGR
 #define INCL_DOSERRORS
 #include <os2.h>
 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)
index 78142bc68f16d75ed289f29846ff74bc1276fe71..f88efa30b4b9edfc6efe34a84701c45a1df7dd36 100644 (file)
@@ -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;
 }
index 91dcb6a52a2f2615cc637d2baed01d5eda3de1ac..c4e09ad9ab3f653b73cd1c4f07dfe9274c32ed48 100644 (file)
 #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 */
index 110ccd837eb707870d629fbca1cdbe8c285f7df8..c3a03c311134e5d8a356b00c3f16c175a9331814 100644 (file)
@@ -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);