]> granicus.if.org Git - file/commitdiff
Bug + portability fixes from the NetBSD build.
authorChristos Zoulas <christos@zoulas.com>
Fri, 2 Jan 2015 21:29:39 +0000 (21:29 +0000)
committerChristos Zoulas <christos@zoulas.com>
Fri, 2 Jan 2015 21:29:39 +0000 (21:29 +0000)
src/apprentice.c
src/cdf.c
src/compress.c
src/file.c
src/file.h
src/funcs.c
src/magic.c
src/print.c
src/readcdf.c
src/readelf.c
src/softmagic.c

index 47b4c870c23aa4e8ab09b84e925877a9dad5d224..595bea00d1b0fe79ce56d0cc9aab08ccda0468b0 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.229 2015/01/01 17:07:34 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.230 2015/01/02 21:29:39 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -2199,7 +2199,7 @@ parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
        size_t i;
        const char *l = line;
        struct magic *m = &me->mp[me->cont_count == 0 ? 0 : me->cont_count - 1];
-       char *buf = (char *)m + off;
+       char *buf = CAST(char *, CAST(void *, m)) + off;
 
        if (buf[0] != '\0') {
                len = nt ? strlen(buf) : len;
@@ -2248,7 +2248,8 @@ parse_apple(struct magic_set *ms, struct magic_entry *me, const char *line)
 {
        struct magic *m = &me->mp[0];
 
-       return parse_extra(ms, me, line, offsetof(struct magic, apple),
+       return parse_extra(ms, me, line,
+           CAST(off_t, offsetof(struct magic, apple)),
            sizeof(m->apple), "APPLE", "!+-./", 0);
 }
 
@@ -2261,7 +2262,8 @@ parse_mime(struct magic_set *ms, struct magic_entry *me, const char *line)
 {
        struct magic *m = &me->mp[0];
 
-       return parse_extra(ms, me, line, offsetof(struct magic, mimetype),
+       return parse_extra(ms, me, line,
+           CAST(off_t, offsetof(struct magic, mimetype)),
            sizeof(m->mimetype), "MIME", "+-/.", 1);
 }
 
index 9e3cf9fd2c6b335808a93c8353bdb0c7f9e60373..e352cc52bbfa077f26d8ed2e5d77c1e074f6a414 100644 (file)
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.69 2014/12/04 15:56:46 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.70 2015/01/02 21:29:39 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -73,8 +73,11 @@ static union {
 #define CDF_TOLE8(x)   ((uint64_t)(NEED_SWAP ? _cdf_tole8(x) : (uint64_t)(x)))
 #define CDF_TOLE4(x)   ((uint32_t)(NEED_SWAP ? _cdf_tole4(x) : (uint32_t)(x)))
 #define CDF_TOLE2(x)   ((uint16_t)(NEED_SWAP ? _cdf_tole2(x) : (uint16_t)(x)))
-#define CDF_TOLE(x)    (sizeof(x) == 2 ? CDF_TOLE2(x) : (sizeof(x) == 4 ? \
-    CDF_TOLE4(x) : CDF_TOLE8(x)))
+#define CDF_TOLE(x)    (/*CONSTCOND*/sizeof(x) == 2 ? \
+                           CDF_TOLE2(CAST(uint16_t, x)) : \
+                       (/*CONSTCOND*/sizeof(x) == 4 ? \
+                           CDF_TOLE4(CAST(uint32_t, x)) : \
+                           CDF_TOLE8(CAST(uint64_t, x))))
 #define CDF_GETUINT32(x, y)    cdf_getuint32(x, y)
 
 
@@ -271,7 +274,7 @@ cdf_check_stream_offset(const cdf_stream_t *sst, const cdf_header_t *h,
        const char *e = ((const char *)p) + tail;
        size_t ss = sst->sst_dirlen < h->h_min_size_standard_stream ?
            CDF_SHORT_SEC_SIZE(h) : CDF_SEC_SIZE(h);
-       (void)&line;
+       /*LINTED*/(void)&line;
        if (e >= b && (size_t)(e - b) <= ss * sst->sst_len)
                return 0;
        DPRINTF(("%d: offset begin %p < end %p || %" SIZE_T_FORMAT "u"
@@ -998,9 +1001,9 @@ cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h,
 }
 
 
-#define extract_catalog_field(f, l) \
+#define extract_catalog_field(t, f, l) \
     memcpy(&ce[i].f, b + (l), sizeof(ce[i].f)); \
-    ce[i].f = CDF_TOLE(ce[i].f)
+    ce[i].f = CAST(t, CDF_TOLE(ce[i].f))
 
 int
 cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst,
@@ -1028,18 +1031,17 @@ cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst,
        ce = (*cat)->cat_e;
        b = CAST(const char *, sst->sst_tab);
        for (i = 0; i < nr; i++) {
-               extract_catalog_field(ce_namlen, 0);
-               extract_catalog_field(ce_num, 2);
-               extract_catalog_field(ce_timestamp, 6);
+               extract_catalog_field(uint16_t, ce_namlen, 0);
+               extract_catalog_field(uint16_t, ce_num, 2);
+               extract_catalog_field(uint64_t, ce_timestamp, 6);
                reclen = ce[i].ce_namlen;
                ce[i].ce_namlen =
                    sizeof(ce[i].ce_name) / sizeof(ce[i].ce_name[0]) - 1;
                if (ce[i].ce_namlen > reclen - 14)
                        ce[i].ce_namlen = reclen - 14;
-               np = CAST(const uint16_t *, (b + 16));
+               np = CAST(const uint16_t *, CAST(const void *, (b + 16)));
                for (k = 0; k < ce[i].ce_namlen; k++) {
-                       ce[i].ce_name[k] = np[k];
-                       CDF_TOLE2(ce[i].ce_name[k]);
+                       ce[i].ce_name[k] = np[k]; /* XXX: CDF_TOLE2? */
                }
                ce[i].ce_name[ce[i].ce_namlen] = 0;
                b += reclen;
index e968bb452850b369be37f42ab1b091fbfa7a53d3..5c4e3e1995f6c187dd711d664215a3f68e9ee0e3 100644 (file)
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.77 2014/12/12 16:33:01 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.78 2015/01/02 21:29:39 christos Exp $")
 #endif
 
 #include "magic.h"
@@ -383,7 +383,6 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
        int fdin[2], fdout[2];
        int status;
        ssize_t r;
-       pid_t pid;
 
 #ifdef BUILTIN_DECOMPRESS
         /* FIXME: This doesn't cope with bzip2 */
@@ -397,7 +396,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
                file_error(ms, errno, "cannot create pipe");    
                return NODATA;
        }
-       switch (pid = fork()) {
+       switch (fork()) {
        case 0: /* child */
                (void) close(0);
                if (fd != -1) {
index 546fd8bac621db0ea0d5e301937dc2f6dd93b83c..7bdad378a013ea25f7f0419598de8641de522e25 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: file.c,v 1.160 2014/12/16 23:18:40 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.161 2015/01/02 21:29:39 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -130,8 +130,14 @@ private struct {
 
 private char *progname;                /* used throughout              */
 
+#ifdef __dead
+__dead
+#endif
 private void usage(void);
 private void docprint(const char *);
+#ifdef __dead
+__dead
+#endif
 private void help(void);
 
 private int unwrap(struct magic_set *, const char *);
index 01aa37a6b9b0189db49119bcf35b846862af8d0a..b96dd2990b12ac3943c687d26843ded932bd7519 100644 (file)
@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.164 2015/01/01 17:07:34 christos Exp $
+ * @(#)$File: file.h,v 1.165 2015/01/02 21:29:39 christos Exp $
  */
 
 #ifndef __file_h__
@@ -590,5 +590,8 @@ static const char *rcsid(const char *p) { \
 #else
 #define FILE_RCSID(id)
 #endif
+#ifndef __RCSID
+#define __RCSID(a)
+#endif
 
 #endif /* __file_h__ */
index a60ccaaf9cef8a587882513827b654a5cb25e951..83be0cf12add115009403db144b445e2c855b006 100644 (file)
@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.79 2014/12/16 20:52:49 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.80 2015/01/02 21:29:39 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -159,8 +159,9 @@ file_badread(struct magic_set *ms)
 }
 
 #ifndef COMPILE_ONLY
+/*ARGSUSED*/
 protected int
-file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((unused)),
+file_buffer(struct magic_set *ms, int fd, const char *inname __attribute__ ((__unused__)),
     const void *buf, size_t nb)
 {
        int m = 0, rv = 0, looks_text = 0;
@@ -549,9 +550,9 @@ file_printable(char *buf, size_t bufsiz, const char *str)
                if (ptr >= eptr - 3)
                        break;
                *ptr++ = '\\';
-               *ptr++ = ((*s >> 6) & 7) + '0';
-               *ptr++ = ((*s >> 3) & 7) + '0';
-               *ptr++ = ((*s >> 0) & 7) + '0';
+               *ptr++ = ((CAST(unsigned int, *s) >> 6) & 7) + '0';
+               *ptr++ = ((CAST(unsigned int, *s) >> 3) & 7) + '0';
+               *ptr++ = ((CAST(unsigned int, *s) >> 0) & 7) + '0';
        }
        *ptr = '\0';
        return buf;
index d16f8c6ce9d976f53084332830fa1ec0635aca2c..dbea31b3f462e13ad7be955bc239961677c39165 100644 (file)
@@ -33,7 +33,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: magic.c,v 1.91 2014/12/16 23:18:40 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.92 2015/01/02 21:29:39 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -543,19 +543,19 @@ magic_setparam(struct magic_set *ms, int param, const void *val)
 {
        switch (param) {
        case MAGIC_PARAM_INDIR_MAX:
-               ms->indir_max = *(const size_t *)val;
+               ms->indir_max = (uint16_t)*(const size_t *)val;
                return 0;
        case MAGIC_PARAM_NAME_MAX:
-               ms->name_max = *(const size_t *)val;
+               ms->name_max = (uint16_t)*(const size_t *)val;
                return 0;
        case MAGIC_PARAM_ELF_PHNUM_MAX:
-               ms->elf_phnum_max = *(const size_t *)val;
+               ms->elf_phnum_max = (uint16_t)*(const size_t *)val;
                return 0;
        case MAGIC_PARAM_ELF_SHNUM_MAX:
-               ms->elf_shnum_max = *(const size_t *)val;
+               ms->elf_shnum_max = (uint16_t)*(const size_t *)val;
                return 0;
        case MAGIC_PARAM_ELF_NOTES_MAX:
-               ms->elf_notes_max = *(const size_t *)val;
+               ms->elf_notes_max = (uint16_t)*(const size_t *)val;
                return 0;
        default:
                errno = EINVAL;
index fa817986740d7aedf9895f55cec86c76f5462ff2..0ffce747bc645b5fb0927e70ba0d18ee3ed457bf 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: print.c,v 1.76 2013/02/26 18:25:00 christos Exp $")
+FILE_RCSID("@(#)$File: print.c,v 1.77 2015/01/02 21:29:39 christos Exp $")
 #endif  /* lint */
 
 #include <string.h>
@@ -164,6 +164,7 @@ file_mdump(struct magic *m)
                case FILE_MELDATE:
                        (void)fprintf(stderr, "%s,",
                            file_fmttime(m->value.l, 0, tbuf));
+                       break;
                case FILE_QDATE:
                case FILE_LEQDATE:
                case FILE_BEQDATE:
index 635a9263764c184eae45ab1c2f80baca1dcee679..60fc633aa993c22af44b7227c9929b03990b4696 100644 (file)
@@ -26,7 +26,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.49 2014/12/04 15:56:46 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.50 2015/01/02 21:29:39 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -39,6 +39,10 @@ FILE_RCSID("@(#)$File: readcdf.c,v 1.49 2014/12/04 15:56:46 christos Exp $")
 #include "cdf.h"
 #include "magic.h"
 
+#ifndef __arraycount
+#define __arraycount(a) (sizeof(a) / sizeof(a[0]))
+#endif
+
 #define NOTMIME(ms) (((ms)->flags & MAGIC_MIME) == 0)
 
 static const struct nv {
index d159620cec858e33c66c3b6fda5ea731621ca440..49b101e489133e36cd63021fdcea0f5acca2161e 100644 (file)
@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.117 2014/12/16 23:29:42 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.118 2015/01/02 21:29:39 christos Exp $")
 #endif
 
 #ifdef BUILTIN_ELF
@@ -482,6 +482,7 @@ do_note_freebsd_version(struct magic_set *ms, int swap, void *v)
 }
 
 private int
+/*ARGSUSED*/
 do_bid_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
     int swap __attribute__((__unused__)), uint32_t namesz, uint32_t descsz,
     size_t noff, size_t doff, int *flags)
@@ -622,7 +623,7 @@ do_pax_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
                        return 1;
 
                for (i = 0; i < __arraycount(pax); i++) {
-                       if (((1 << i) & desc) == 0)
+                       if (((1 << (int)i) & desc) == 0)
                                continue;
                        if (file_printf(ms, "%s%s", did++ ? "," : "",
                            pax[i]) == -1)
@@ -1008,7 +1009,8 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
        }
 
        /* Read offset of name section to be able to read section names later */
-       if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) < (ssize_t)xsh_sizeof) {
+       if (pread(fd, xsh_addr, xsh_sizeof, CAST(off_t, (off + size * strtab)))
+           < (ssize_t)xsh_sizeof) {
                file_badread(ms);
                return -1;
        }
index 5e277e31fdda21da7d8c0ec73872bad884d07697..c3d8f537d69f0a963e1826a426ac383ce5cc4d68 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.206 2015/01/01 17:07:34 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.207 2015/01/02 21:29:39 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -1666,7 +1666,7 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
 
        case FILE_INDIRECT:
                if (m->str_flags & INDIRECT_RELATIVE)
-                       offset += o;
+                       offset += CAST(uint32_t, o);
                if (offset == 0)
                        return 0;