--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
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;
* 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]);
}
}
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. */
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;
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);
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;
* 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;
/*@notreached@*/
}
- while (fgets(buf, MAXPATHLEN, f) != NULL) {
+ while (fgets(buf, sizeof(buf), f) != NULL) {
cwid = strlen(buf) - 1;
if (cwid > wid)
wid = cwid;
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';
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':
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@*/
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 */
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@*/
}
exit:
+ if (fm->buf != NULL)
+ free(fm->buf);
fm->buf = NULL;
fm->nb = 0;
return ret;
}
#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)
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;
*/
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;
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;
*/
static int
fmagicSConvert(fmagic fm, struct magic *m)
- /*@modifies fm @*/
+ /*@globals fileSystem @*/
+ /*@modifies fm, fileSystem @*/
{
union VALUETYPE * p = &fm->val;
/*@=declundef @*/
#endif
-#if HAVE_ERROR && HAVE_ERROR_H
-#include <error.h>
-#endif
-
#if defined(__LCLINT__)
/*@-declundef @*/
/*@exits@*/
/*@globals fileSystem @*/
/*@modifies fileSystem @*/;
/*@=declundef @*/
+#else
+#if HAVE_ERROR && HAVE_ERROR_H
+#include <error.h>
+#endif
#endif
#ifdef STDC_HEADERS
#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)
#endif
/* XXX solaris2.5.1 has not */
-#if !defined(EXIT_FAILURE)
+#if !defined(EXIT_FAILURE) && !defined(__LCLINT__)
#define EXIT_FAILURE 1
#endif
*/
/*@unused@*/ /*@exits@*/ /*@only@*/
static inline void * vmefail(/*@unused@*/ size_t nb)
- /*@*/
+ /*@globals fileSystem @*/
+ /*@modifies fileSystem @*/
{
error(EXIT_FAILURE, 0, "out of memory");
/*@notreached@*/