MOre annotations.
authorjbj <devnull@localhost>
Tue, 19 Nov 2002 13:50:55 +0000 (13:50 +0000)
committerjbj <devnull@localhost>
Tue, 19 Nov 2002 13:50:55 +0000 (13:50 +0000)
CVS patchset: 5874
CVS date: 2002/11/19 13:50:55

file/.splintrc [moved from file/.lclintrc with 53% similarity]
file/apprentice.c
file/ascmagic.c
file/file.c
file/file.h
file/fsmagic.c
file/print.c
file/readelf.c
file/softmagic.c
file/system.h

similarity index 53%
rename from file/.lclintrc
rename to file/.splintrc
index cb79208..2e758c9 100644 (file)
@@ -1,4 +1,4 @@
--I. -DHAVE_CONFIG_H -DSTDC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGFILE_SOURCE -D__GLIBC__ -D__STDC__=1 -DHAVE_STRUCT_STAT_ST_RDEV -DSIZEOF_UINT64_T=8
+-I. -DHAVE_CONFIG_H -DSTDC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGFILE_SOURCE -D__STDC__=1 -DHAVE_STRUCT_STAT_ST_RDEV -DSIZEOF_UINT64_T=8
 
 #+partial
 +forcehints
 +strict                        # lclint level
 
 # --- in progress
--compdef
--compmempass
--exportheader          # 19
+-compmempass           # 7
+-exportheader          # 50
 -formatconst           # 1
--macroredef            # 20 tar.h
-#-noeffect
--nullderef             # 4
--nullpass              # 22
+-globstate             # 3
+-macroredef            # 1 tar.h
+-nullderef             # 1
+-nullpass              # 5
 -nullptrarith          # 1
 -redef                 # 1 tar.h
--sizeoftype            # 29
--uniondef              # 6
-
-# --- +partial artifacts
+-sizeoftype            # 14
 
 # --- not-yet at strict level
--bitwisesigned         # 47
--elseifcomplete                # 3
-#-fielduse             # 21 tar.h
+-bitwisesigned         # 86
+-elseifcomplete                # 2
 -forblock              # 6
 -ifblock               # 231
--incondefs             # 36
+-incondefs             # 64
 -namechecks            # tedious ANSI compliance checks
 -ptrarith              # tedious
 
--mustdefine
+-mustdefine            # 25
 -shiftimplementation   # 148 ctype.h
 
--strictops             # 4
--whileblock            # 17
+-strictops             # 37
+-whileblock            # 16
 
 # --- not-yet at checks level
--mustfree              # 17
--usedef                        # 41
+-mustfree              # 26
+-usedef                        # 31
 
 # --- not-yet at standard level
--predboolint
-+boolint               # 36
++boolint               # 38
 +charint               # 147
 +ignorequals           # 49
-+matchanyintegral      # 83
++matchanyintegral      # 77
index 2d8f4a5..4212256 100644 (file)
@@ -298,10 +298,10 @@ parse(/*@out@*/ struct magic **magicp, /*@out@*/ uint32_t *nmagicp,
        if (*nmagicp + 1 >= maxmagic){
                maxmagic += ALLOC_INCR;
 /*@-unqualifiedtrans @*/
-               *magicp = xrealloc(*magicp, sizeof(struct magic) * maxmagic);
+               *magicp = xrealloc(*magicp, sizeof(**magicp) * maxmagic);
 /*@=unqualifiedtrans @*/
                m = &(*magicp)[*nmagicp];
-               memset(m, 0, sizeof(struct magic) * ALLOC_INCR);
+               memset(m, 0, sizeof(**magicp) * ALLOC_INCR);
        } else
                m = &(*magicp)[*nmagicp];
        m->flag = 0;
@@ -749,10 +749,11 @@ void bs1(struct magic *m)
  * Byteswap an mmap'ed file if needed
  */
 static void
-byteswap(struct magic *m, uint32_t nmagic)
+byteswap(/*@null@*/ struct magic *m, uint32_t nmagic)
        /*@modifies m @*/
 {
        uint32_t i;
+       if (m != NULL)
        for (i = 0; i < nmagic; i++)
                bs1(&m[i]);
 }
@@ -801,7 +802,7 @@ apprentice_file(fmagic fm, /*@out@*/ struct magic **magicp,
        }
 
         maxmagic = MAXMAGIS;
-       *magicp = (struct magic *) xcalloc(sizeof(struct magic), maxmagic);
+       *magicp = (struct magic *) xcalloc(sizeof(**magicp), maxmagic);
 
        /* parse it */
        if (action == CHECK)    /* print silly verbose header for USG compat. */
@@ -858,14 +859,14 @@ apprentice_compile(/*@unused@*/ const fmagic fm,
                return -1;
        }
 
-       if (lseek(fd, sizeof(struct magic), SEEK_SET) != sizeof(struct magic)) {
+       if (lseek(fd, sizeof(**magicp), SEEK_SET) != sizeof(**magicp)) {
                (void)fprintf(stderr, "%s: error seeking `%s' (%s)\n",
                    progname, dbname, strerror(errno));
                return -1;
        }
 
-       if (write(fd, *magicp,  sizeof(struct magic) * *nmagicp) 
-           != sizeof(struct magic) * *nmagicp) {
+       if (write(fd, *magicp,  sizeof(**magicp) * *nmagicp) 
+           != sizeof(**magicp) * *nmagicp) {
                (void)fprintf(stderr, "%s: error writing `%s' (%s)\n",
                    progname, dbname, strerror(errno));
                return -1;
@@ -943,7 +944,7 @@ apprentice_map(/*@unused@*/ const fmagic fm,
                    progname, version, VERSIONNO, dbname);
                goto errxit;
        }
-       *nmagicp = (st.st_size / sizeof(struct magic)) - 1;
+       *nmagicp = (st.st_size / sizeof(**magicp)) - 1;
        (*magicp)++;
        if (needsbyteswap)
                byteswap(*magicp, *nmagicp);
@@ -999,11 +1000,11 @@ apprentice_1(fmagic fm, const char *fn, int action)
        if (rv != 0)
                return rv;
             
-       ml = xmalloc(sizeof(*ml));
-
        if (magic == NULL || nmagic == 0)
                return rv;
 
+       ml = xmalloc(sizeof(*ml));
+
        ml->magic = magic;
        ml->nmagic = nmagic;
 
index 2ff8806..70f6195 100644 (file)
@@ -637,6 +637,8 @@ fmagicA(fmagic fm)
                 * compare the word thus isolated against the token list
                 */
                for (p = names; p < names + NNAMES; p++) {
+                       if (p->name == NULL)
+                               /*@innerbreak@*/ break;
                        if (fmagicAMatch(p->name, ubuf + i, end - i)) {
                                subtype = types[p->type].human;
                                subtype_mime = types[p->type].mime;
index e0cd9d1..33cf289 100644 (file)
@@ -88,7 +88,7 @@ unwrap(fmagic fm, char *fn)
                        /*@notreached@*/
                }
 
-               while (fgets(buf, MAXPATHLEN, f) != NULL) {
+               while (fgets(buf, sizeof(buf), f) != NULL) {
                        cwid = strlen(buf) - 1;
                        if (cwid > wid)
                                wid = cwid;
@@ -97,7 +97,7 @@ unwrap(fmagic fm, char *fn)
                rewind(f);
        }
 
-       while (fgets(buf, MAXPATHLEN, f) != NULL) {
+       while (fgets(buf, sizeof(buf), f) != NULL) {
                buf[strlen(buf)-1] = '\0';
                fm->obp = fm->obuf;
                *fm->obp = '\0';
@@ -281,8 +281,10 @@ main(int argc, char **argv)
                case 'i':
                        fm->flags |= FMAGIC_FLAGS_MIME;
                        mime = malloc(strlen(fm->magicfile) + sizeof(".mime"));
-                       (void)strcpy(mime, fm->magicfile);
-                       (void)strcat(mime, ".mime");
+                       if (mime != NULL) {
+                               (void)strcpy(mime, fm->magicfile);
+                               (void)strcat(mime, ".mime");
+                       }
                        fm->magicfile = mime;
                        /*@switchbreak@*/ break;
                case 'k':
index c58f003..a21ffa2 100644 (file)
@@ -108,13 +108,13 @@ struct magic {
 struct mlist {
        struct magic *magic;            /* array of magic entries */
        uint32_t nmagic;                /* number of entries in array */
-/*@null@*/
+/*@relnull@*/
        struct mlist *next;
-/*@null@*/
+/*@relnull@*/
        struct mlist *prev;
 };
 
-/*@unchecked@*/ /*@observer@*/ /*@null@*/
+/*@unchecked@*/ /*@observer@*/ /*@relnull@*/
 extern char *progname;         /* the program name                     */
 /*@unchecked@*/
 
@@ -133,12 +133,12 @@ enum fmagicFlags_e {
 
 struct fmagic_s {
     int flags;                 /*!< bit(s) to control fmagic behavior. */
-/*@dependent@*/ /*@observer@*/ /*@null@*/
+/*@dependent@*/ /*@observer@*/ /*@relnull@*/
     const char *magicfile;     /*!< name of the magic file             */
     int lineno;                        /*!< current line number in magic file  */
-/*@null@*/
+/*@relnull@*/
     struct mlist * mlist;      /*!< list of arrays of magic entries    */
-/*@null@*/
+/*@relnull@*/
     struct mlist * ml;         /*!< current magic array item           */
 /*@observer@*/
     const char * fn;           /*!< current file name                  */
index bf46610..41ed54b 100644 (file)
@@ -268,14 +268,14 @@ int
 fmagicProcess(fmagic fm, const char *fn, int wid)
 {
        static  const char stdname[] = "standard input";
-       unsigned char   b[HOWMANY+1];   /* one extra for terminating '\0' */
        char match = '\0';
        int ret = 0;
 
 /*@-assignexpose -temptrans @*/
        fm->fn = fn;
 /*@=assignexpose =temptrans @*/
-       fm->buf = b;
+       fm->buf = xmalloc(HOWMANY+1);
+       fm->buf[0] = '\0';
        fm->nb = 0;
 
 /*@-branchstate@*/
@@ -369,6 +369,8 @@ fmagicProcess(fmagic fm, const char *fn, int wid)
        }
 
 exit:
+       if (fm->buf != NULL)
+               free(fm->buf);
        fm->buf = NULL;
        fm->nb = 0;
        return ret;
index 3af7fcc..43ba450 100644 (file)
@@ -129,23 +129,23 @@ mdump(struct magic *m)
 }
 #endif
 
-#if !defined(HAVE_ERROR)
+#if !defined(HAVE_ERROR) || defined(__LCLINT__)
 /*
  * error - print best error message possible and exit
  */
 /*VARARGS*/
 void
-error(int status, int errnum, const char *fmt, ...)
+error(int status, /*@unused@*/ int errnum, const char * format, ...)
 {
        va_list va;
 
-       va_start(va, fmt);
+       va_start(va,  format);
        /* cuz we use stdout for most, stderr here */
        (void) fflush(stdout); 
 
        if (progname != NULL) 
                (void) fprintf(stderr, "%s: ", progname);
-       (void) vfprintf(stderr, fmt, va);
+       (void) vfprintf(stderr,  format, va);
        va_end(va);
 #if NOTYET
        if (status)
index db09346..9c728ca 100644 (file)
@@ -110,7 +110,8 @@ getu64(const fmagic fm, uint64_t value)
 
 static void
 doshn(fmagic fm, off_t off, int num, size_t size)
-       /*@modifies fm @*/
+       /*@globals fileSystem @*/
+       /*@modifies fm, fileSystem @*/
 {
        Elf32_Shdr sh32;
        Elf64_Shdr sh64;
@@ -140,7 +141,8 @@ doshn(fmagic fm, off_t off, int num, size_t size)
  */
 static void
 dophn_exec(fmagic fm, off_t off, int num, size_t size)
-       /*@modifies fm @*/
+       /*@globals fileSystem @*/
+       /*@modifies fm, fileSystem @*/
 {
        Elf32_Phdr ph32;
        Elf32_Nhdr *nh32 = NULL;
@@ -339,7 +341,8 @@ static const char *os_style_names[] = {
 
 static void
 dophn_core(fmagic fm, off_t off, int num, size_t size)
-       /*@modifies fm @*/
+       /*@globals fileSystem @*/
+       /*@modifies fm, fileSystem @*/
 {
        Elf32_Phdr ph32;
        Elf32_Nhdr *nh32 = NULL;
index 8b9c6f6..a973f4c 100644 (file)
@@ -114,7 +114,8 @@ fmagicSPrint(const fmagic fm, struct magic *m)
  */
 static int
 fmagicSConvert(fmagic fm, struct magic *m)
-       /*@modifies fm @*/
+       /*@globals fileSystem @*/
+       /*@modifies fm, fileSystem @*/
 {
        union VALUETYPE * p = &fm->val;
 
index 2b2d6f1..a89a54e 100644 (file)
@@ -41,10 +41,6 @@ extern int errno;
 /*@=declundef @*/
 #endif
 
-#if HAVE_ERROR && HAVE_ERROR_H
-#include <error.h>
-#endif
-
 #if defined(__LCLINT__)
 /*@-declundef @*/
 /*@exits@*/
@@ -53,6 +49,10 @@ extern void error(int status, int errnum, const char *format, ...)
        /*@globals fileSystem @*/
        /*@modifies fileSystem @*/;
 /*@=declundef @*/
+#else
+#if HAVE_ERROR && HAVE_ERROR_H
+#include <error.h>
+#endif
 #endif
 
 #ifdef STDC_HEADERS
@@ -65,7 +65,7 @@ extern void error(int status, int errnum, const char *format, ...)
 #include <varargs.h>
 #endif /* STDC_HEADERS */
 
-#if defined (__GLIBC__) && defined(__LCLINT__)
+#if defined(__LCLINT__)
 /*@-declundef@*/
 /*@-exportfcn@*/
 extern __const unsigned short int **__ctype_b_loc (void)
@@ -107,7 +107,7 @@ extern int _tolower(int) __THROW    /*@*/;
 #endif
 
 /* XXX solaris2.5.1 has not */
-#if !defined(EXIT_FAILURE)
+#if !defined(EXIT_FAILURE) && !defined(__LCLINT__)
 #define        EXIT_FAILURE    1
 #endif
 
@@ -245,7 +245,8 @@ char * xstrdup (const char *str)
  */
 /*@unused@*/ /*@exits@*/ /*@only@*/
 static inline void * vmefail(/*@unused@*/ size_t nb)
-       /*@*/
+       /*@globals fileSystem @*/
+       /*@modifies fileSystem @*/
 {
        error(EXIT_FAILURE, 0, "out of memory");
        /*@notreached@*/