]> granicus.if.org Git - file/commitdiff
- use SIZE_T_FORMAT instead of 'z' in size_t format strings
authorChristos Zoulas <christos@zoulas.com>
Mon, 15 Oct 2018 16:29:16 +0000 (16:29 +0000)
committerChristos Zoulas <christos@zoulas.com>
Mon, 15 Oct 2018 16:29:16 +0000 (16:29 +0000)
- compile with c++ again

src/ascmagic.c
src/cdf.c
src/compress.c
src/der.c
src/encoding.c
src/file.h
src/is_json.c
src/is_tar.c
src/readcdf.c
src/readelf.c
src/softmagic.c

index 686fa957efa4a0eb9917763c9d106ddc3b34c295..fd38f1bc611c33a953bcac5d30e678ee04d2cfed 100644 (file)
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.99 2018/09/09 20:33:28 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.100 2018/10/15 16:29:16 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -80,7 +80,7 @@ file_ascmagic(struct magic_set *ms, const struct buffer *b, int text)
        const char *type = NULL;
 
        bb = *b;
-       bb.flen = trim_nuls(b->fbuf, b->flen);
+       bb.flen = trim_nuls(CAST(const unsigned char *, b->fbuf), b->flen);
 
        /* If file doesn't look like any sort of text, give up. */
        if (file_encoding(ms, &bb, &ubuf, &ulen, &code, &code_mime,
@@ -101,7 +101,7 @@ file_ascmagic_with_encoding(struct magic_set *ms,
     const char *type, int text)
 {
        struct buffer bb;
-       const unsigned char *buf = b->fbuf;
+       const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
        size_t nbytes = b->flen;
        unsigned char *utf8_buf = NULL, *utf8_end;
        size_t mlen, i;
index 47ccbd5148bd6f6d625800da7d8b3708f116ff1c..3cba3ac567ee659365d87b9a9f0d6f9e3287f794 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.112 2018/10/01 18:45:39 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.113 2018/10/15 16:29:16 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -88,7 +88,8 @@ static void *
 cdf_malloc(const char *file __attribute__((__unused__)),
     size_t line __attribute__((__unused__)), size_t n)
 {
-       DPRINTF(("%s,%zu: %s %zu\n", file, line, __func__, n));
+       DPRINTF(("%s,%" SIZE_T_FORMAT "u: %s %" SIZE_T_FORMAT "u\n",
+           file, line, __func__, n));
        return malloc(n);
 }
 
@@ -97,7 +98,8 @@ static void *
 cdf_realloc(const char *file __attribute__((__unused__)),
     size_t line __attribute__((__unused__)), void *p, size_t n)
 {
-       DPRINTF(("%s,%zu: %s %zu\n", file, line, __func__, n));
+       DPRINTF(("%s,%" SIZE_T_FORMAT "u: %s %" SIZE_T_FORMAT "u\n",
+           file, line, __func__, n));
        return realloc(p, n);
 }
 
@@ -106,7 +108,8 @@ static void *
 cdf_calloc(const char *file __attribute__((__unused__)),
     size_t line __attribute__((__unused__)), size_t n, size_t u)
 {
-       DPRINTF(("%s,%zu: %s %zu %zu\n", file, line, __func__, n, u));
+       DPRINTF(("%s,%" SIZE_T_FORMAT "u: %s %" SIZE_T_FORMAT "u %"
+           SIZE_T_FORMAT "u\n", file, line, __func__, n, u));
        return calloc(n, u);
 }
 
@@ -484,8 +487,9 @@ cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
                        if (sec < 0)
                                goto out;
                        if (i >= sat->sat_len) {
-                           DPRINTF(("Out of bounds reading MSA %" SIZE_T_FORMAT
-                               "u >= %" SIZE_T_FORMAT "u", i, sat->sat_len));
+                           DPRINTF(("Out of bounds reading MSA %"
+                               SIZE_T_FORMAT "u >= %" SIZE_T_FORMAT "u",
+                               i, sat->sat_len));
                            goto out3;
                        }
                        if (cdf_read_sector(info, sat->sat_tab, ss * i, ss, h,
@@ -894,8 +898,8 @@ cdf_grow_info(cdf_property_info_t **info, size_t *maxcount, size_t incr)
        size_t newcount = *maxcount + incr;
 
        if (newcount > CDF_PROP_LIMIT) {
-               DPRINTF(("exceeded property limit %zu > %zu\n",
-                   newcount, CDF_PROP_LIMIT));
+               DPRINTF(("exceeded property limit %" SIZE_T_FORMAT "u > %"
+                   SIZE_T_FORMAT "u\n", newcount, CDF_PROP_LIMIT));
                goto out;
        }
        inp = CAST(cdf_property_info_t *,
@@ -1063,10 +1067,10 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
                                inp[i].pi_str.s_buf = CAST(const char *,
                                    CAST(const void *, &q[o4]));
 
-                               DPRINTF(("o=%zu l=%d(%" SIZE_T_FORMAT
-                                   "u), t=%zu s=%s\n", o4, l,
-                                   CDF_ROUND(l, sizeof(l)), left,
-                                   inp[i].pi_str.s_buf));
+                               DPRINTF(("o=%" SIZE_T_FORMAT "u l=%d(%"
+                                   SIZE_T_FORMAT "u), t=%" SIZE_T_FORMAT
+                                   "u s=%s\n", o4, l, CDF_ROUND(l, sizeof(l)),
+                                   left, inp[i].pi_str.s_buf));
 
                                if (l & 1)
                                        l++;
index f7d9d1c182d17b5adf3afd73594fedc244440564..d229219d2361a6a2093f0dba768bcca0870f4d42 100644 (file)
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.112 2018/10/01 18:43:01 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.113 2018/10/15 16:29:16 christos Exp $")
 #endif
 
 #include "magic.h"
@@ -149,7 +149,7 @@ private const struct {
        const void *magic;
        size_t maglen;
        const char **argv;
-
+       void *unused;
 } compr[] = {
        { "\037\235",   2, gzip_args, NULL },           /* compressed */
        /* Uncompress can get stuck; so use gzip first if we have it
@@ -224,7 +224,7 @@ file_zmagic(struct magic_set *ms, const struct buffer *b, const char *name)
        int urv, prv, rv = 0;
        int mime = ms->flags & MAGIC_MIME;
        int fd = b->fd;
-       const unsigned char *buf = b->fbuf;
+       const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
        size_t nbytes = b->flen;
        sig_t osigpipe;
 
@@ -248,8 +248,8 @@ file_zmagic(struct magic_set *ms, const struct buffer *b, const char *name)
                        continue;
                nsz = nbytes;
                urv = uncompressbuf(fd, ms->bytes_max, i, buf, &newbuf, &nsz);
-               DPRINTF("uncompressbuf = %d, %s, %zu\n", urv, (char *)newbuf,
-                   nsz);
+               DPRINTF("uncompressbuf = %d, %s, %" SIZE_T_FORMAT "u\n", urv,
+                   (char *)newbuf, nsz);
                switch (urv) {
                case OKDATA:
                case ERRDATA:
@@ -785,7 +785,7 @@ err:
        }
 
        closefd(fdp[STDIN_FILENO], 0);
-       DPRINTF("Returning %p n=%zu rv=%d\n", *newch, *n, rv);
+       DPRINTF("Returning %p n=%" SIZE_T_FORMAT "u rv=%d\n", *newch, *n, rv);
 
        return rv;
 }
index 5ccd8997a384311222c4302a3a80e5aad4a6119d..cc277696a827bb254afd51e6d3eb23e3145457f5 100644 (file)
--- a/src/der.c
+++ b/src/der.c
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: der.c,v 1.14 2018/09/09 20:33:28 christos Exp $")
+FILE_RCSID("@(#)$File: der.c,v 1.15 2018/10/15 16:29:16 christos Exp $")
 #endif
 #endif
 
@@ -245,18 +245,21 @@ der_offs(struct magic_set *ms, struct magic *m, size_t nbytes)
 
        if (gettag(b, &offs, len) == DER_BAD)
                return -1;
-       DPRINTF(("%s1: %d %zu %u\n", __func__, ms->offset, offs, m->offset));
+       DPRINTF(("%s1: %d %" SIZE_T_FORMAT "u %u\n", __func__, ms->offset,
+           offs, m->offset));
 
        uint32_t tlen = getlength(b, &offs, len);
        if (tlen == DER_BAD)
                return -1;
-       DPRINTF(("%s2: %d %zu %u\n", __func__, ms->offset, offs, tlen));
+       DPRINTF(("%s2: %d %" SIZE_T_FORMAT "u %u\n", __func__, ms->offset,
+           offs, tlen));
 
        offs += ms->offset + m->offset;
        DPRINTF(("cont_level = %d\n", m->cont_level));
 #ifdef DEBUG_DER
        for (size_t i = 0; i < m->cont_level; i++)
-               printf("cont_level[%zu] = %u\n", i, ms->c.li[i].off);
+               printf("cont_level[%" SIZE_T_FORMAT "u] = %u\n", i,
+                   ms->c.li[i].off);
 #endif
        if (m->cont_level != 0) {
                if (offs + tlen > nbytes)
@@ -312,14 +315,15 @@ again:
                        slen = slen * 10 + *s - '0';
                while (isdigit((unsigned char)*++s));
                if ((ms->flags & MAGIC_DEBUG) != 0)
-                       fprintf(stderr, "%s: len %zu %u\n", __func__,
-                           slen, tlen);
+                       fprintf(stderr, "%s: len %" SIZE_T_FORMAT "u %u\n",
+                           __func__, slen, tlen);
                if (tlen != slen)
                        return 0;
                goto again;
        }
 val:
-       DPRINTF(("%s: before data %zu %u\n", __func__, offs, tlen));
+       DPRINTF(("%s: before data %" SIZE_T_FORMAT "u %u\n", __func__, offs,
+           tlen));
        der_data(buf, sizeof(buf), tag, b + offs, tlen);
        if ((ms->flags & MAGIC_DEBUG) != 0)
                fprintf(stderr, "%s: data %s %s\n", __func__, buf, s);
@@ -368,7 +372,8 @@ printdata(size_t level, const void *v, size_t x, size_t l)
                        break;
                uint32_t len = getlength(p, &x, ep - p + x);
 
-               printf("%zu %zu-%zu %c,%c,%s,%u:", level, ox, x,
+               printf("%" SIZE_T_FORMAT "u %" SIZE_T_FORMAT "u-%"
+                   SIZE_T_FORMAT "u %c,%c,%s,%u:", level, ox, x,
                    der_class[c], der_type[t],
                    der_tag(buf, sizeof(buf), tag), len);
                q = p + x;
index 3e7b9e584b08e15cceef9ef32fd456f862957a18..ef8493d52eab323dfc7d6447619c5251ec32bb01 100644 (file)
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: encoding.c,v 1.14 2017/11/02 20:25:39 christos Exp $")
+FILE_RCSID("@(#)$File: encoding.c,v 1.15 2018/10/15 16:29:16 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -69,7 +69,7 @@ protected int
 file_encoding(struct magic_set *ms, const struct buffer *b, unichar **ubuf,
     size_t *ulen, const char **code, const char **code_mime, const char **type)
 {
-       const unsigned char *buf = b->fbuf;
+       const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
        size_t nbytes = b->flen;
        size_t mlen;
        int rv = 1, ucs_type;
index 3898726101f26386bc3987ba0576ac87d49a63b8..ce2ff7d9970bed537a788aec2cd1955050c09b71 100644 (file)
@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.198 2018/10/01 18:45:39 christos Exp $
+ * @(#)$File: file.h,v 1.199 2018/10/15 16:29:16 christos Exp $
  */
 
 #ifndef __file_h__
@@ -40,6 +40,9 @@
 #ifndef __STDC_LIMIT_MACROS
 #define __STDC_LIMIT_MACROS
 #endif
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
 
 #ifdef WIN32
   #ifdef _WIN64
index a530cba70c8e374115cbcc190687dbef9fcff980..b2acc38e1ebb40174be22fa02bd37b51d19a60b1 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: is_json.c,v 1.10 2018/09/09 20:33:28 christos Exp $")
+FILE_RCSID("@(#)$File: is_json.c,v 1.11 2018/10/15 16:29:16 christos Exp $")
 #endif
 
 #include <string.h>
@@ -381,7 +381,7 @@ out:
 int
 file_is_json(struct magic_set *ms, const struct buffer *b)
 {
-       const unsigned char *uc = b->fbuf;
+       const unsigned char *uc = CAST(const unsigned char *, b->fbuf);
        const unsigned char *ue = uc + b->flen;
        size_t st[JSON_MAX];
        int mime = ms->flags & MAGIC_MIME;
@@ -406,9 +406,11 @@ file_is_json(struct magic_set *ms, const struct buffer *b)
                return -1;
 #if JSON_COUNT
 #define P(n) st[n], st[n] > 1 ? "s" : ""
-       if (file_printf(ms, " (%zu object%s, %zu array%s, %zu string%s, "
-           "%zu constant%s, %zu number%s)", P(JSON_OBJECT), P(JSON_ARRAY),
-           P(JSON_STRING), P(JSON_CONSTANT), P(JSON_NUMBER)) == -1)
+       if (file_printf(ms, " (%" SIZE_T_FORMAT "u object%s, %" SIZE_T_FORMAT
+           "u array%s, %" SIZE_T_FORMAT "u string%s, %" SIZE_T_FORMAT
+           "u constant%s, %" SIZE_T_FORMAT "u number%s)", P(JSON_OBJECT),
+           P(JSON_ARRAY), P(JSON_STRING), P(JSON_CONSTANT), P(JSON_NUMBER))
+           == -1)
                return -1;
 #endif
        return 1;
index 8c8158210156d18cb624ae76b83a8594d7ef1566..2f67245bb6783a755e8028aeb16d9ed400fab907 100644 (file)
@@ -40,7 +40,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: is_tar.c,v 1.42 2018/08/01 08:50:20 christos Exp $")
+FILE_RCSID("@(#)$File: is_tar.c,v 1.43 2018/10/15 16:29:16 christos Exp $")
 #endif
 
 #include "magic.h"
@@ -62,7 +62,7 @@ static const char tartype[][32] = {   /* should be equal to messages */
 protected int
 file_is_tar(struct magic_set *ms, const struct buffer *b)
 {
-       const unsigned char *buf = b->fbuf;
+       const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
        size_t nbytes = b->flen;
        /*
         * Do the tar test first, because if the first file in the tar
index 2de63b96342fac630e8f43b892de36fe988d31be..b43a84321e47905fbbe59c14868051ca843d1e5e 100644 (file)
@@ -26,7 +26,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.70 2018/09/09 20:33:28 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.71 2018/10/15 16:29:16 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -540,7 +540,7 @@ protected int
 file_trycdf(struct magic_set *ms, const struct buffer *b)
 {
        int fd = b->fd;
-       const unsigned char *buf = b->fbuf;
+       const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
        size_t nbytes = b->flen;
        cdf_info_t info;
        cdf_header_t h;
index 89a71a617a12f4d47f12485b65dc7d68c95cc86b..909e4148bb3e2f9777be1aa026905002b01c35b3 100644 (file)
@@ -27,7 +27,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.153 2018/09/11 00:37:33 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.154 2018/10/15 16:29:16 christos Exp $")
 #endif
 
 #ifdef BUILTIN_ELF
@@ -757,7 +757,7 @@ do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
                        if (file_printf(ms, ", from '%.31s', pid=%u, uid=%u, "
                            "gid=%u, nlwps=%u, lwp=%u (signal %u/code %u)",
                            file_printable(sbuf, sizeof(sbuf),
-                           CAST(char *, pi.cpi_name)),
+                           RCAST(char *, pi.cpi_name)),
                            elf_getu32(swap, (uint32_t)pi.cpi_pid),
                            elf_getu32(swap, pi.cpi_euid),
                            elf_getu32(swap, pi.cpi_egid),
@@ -1203,7 +1203,7 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
                        return offset;
        }
 
-       if (namesz == 7 && strcmp(CAST(char *, &nbuf[noff]), "NetBSD") == 0) {
+       if (namesz == 7 && strcmp(RCAST(char *, &nbuf[noff]), "NetBSD") == 0) {
                int descw, flag;
                const char *str, *tag;
                if (descsz > 100)
@@ -1234,7 +1234,7 @@ donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
 
                if (*flags & flag)
                        return offset;
-               str = CAST(const char *, &nbuf[doff]);
+               str = RCAST(const char *, &nbuf[doff]);
                descw = CAST(int, descsz);
                *flags |= flag;
                file_printf(ms, ", %s: %.*s", tag, descw, str);
@@ -1707,7 +1707,7 @@ protected int
 file_tryelf(struct magic_set *ms, const struct buffer *b)
 {
        int fd = b->fd;
-       const unsigned char *buf = b->fbuf;
+       const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
        size_t nbytes = b->flen;
        union {
                int32_t l;
@@ -1729,7 +1729,8 @@ file_tryelf(struct magic_set *ms, const struct buffer *b)
         * file locations and thus file(1) cannot determine it from easily.
         * Instead we traverse thru all section headers until a symbol table
         * one is found or else the binary is stripped.
-        * Return immediately if it's not ELF (so we avoid pipe2file unless needed).
+        * Return immediately if it's not ELF (so we avoid pipe2file unless
+        * needed).
         */
        if (buf[EI_MAG0] != ELFMAG0
            || (buf[EI_MAG1] != ELFMAG1 && buf[EI_MAG1] != OLFMAG1)
index 7d48db5a733e5db8c35bf57c66ebf5d7d1542c67..9cdbe9afe9cec4cbca01319cc17107dfb7e8f453 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.270 2018/09/09 20:33:28 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.271 2018/10/15 16:29:16 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -206,7 +206,8 @@ flush:
                ms->line = m->lineno;
 
                /* if main entry matches, print it... */
-               switch (mget(ms, m, b, bb.fbuf, bb.flen, offset, cont_level,
+               switch (mget(ms, m, b, CAST(const unsigned char *, bb.fbuf),
+                   bb.flen, offset, cont_level,
                    mode, text, flip, indir_count, name_count,
                    printed_something, need_separator, returnval)) {
                case -1:
@@ -299,7 +300,8 @@ flush:
                                        continue;
                        }
 #endif
-                       switch (mget(ms, m, b, bb.fbuf, bb.flen, offset,
+                       switch (mget(ms, m, b, CAST(const unsigned char *,
+                           bb.fbuf), bb.flen, offset,
                            cont_level, mode, text, flip, indir_count,
                            name_count, printed_something, need_separator,
                            returnval)) {
@@ -897,8 +899,8 @@ moffset(struct magic_set *ms, struct magic *m, const struct buffer *b,
                        if (o == -1 || (size_t)o > nbytes) {
                                if ((ms->flags & MAGIC_DEBUG) != 0) {
                                        (void)fprintf(stderr,
-                                           "Bad DER offset %d nbytes=%zu",
-                                           o, nbytes);
+                                           "Bad DER offset %d nbytes=%"
+                                           SIZE_T_FORMAT "u", o, nbytes);
                                }
                                *op = 0;
                                return 0;
@@ -913,8 +915,8 @@ moffset(struct magic_set *ms, struct magic *m, const struct buffer *b,
 
        if ((size_t)o > nbytes) {
 #if 0
-               file_error(ms, 0, "Offset out of range %zu > %zu",
-                   (size_t)o, nbytes);
+               file_error(ms, 0, "Offset out of range %" SIZE_T_FORMAT
+                   "u > %" SIZE_T_FORMAT "u", (size_t)o, nbytes);
 #endif
                return -1;
        }
@@ -1426,8 +1428,8 @@ msetoffset(struct magic_set *ms, struct magic *m, struct buffer *bb,
                        return -1;
                if (o != 0) {
                        // Not yet!
-                       file_magerror(ms, "non zero offset %zu at"
-                           " level %u", o, cont_level);
+                       file_magerror(ms, "non zero offset %" SIZE_T_FORMAT
+                           "u at level %u", o, cont_level);
                        return -1;
                }
                if ((size_t)-m->offset > b->elen)
@@ -1446,7 +1448,8 @@ normal:
                }
        }
        if ((ms->flags & MAGIC_DEBUG) != 0) {
-               fprintf(stderr, "bb=[%p,%zu], %d [b=%p,%zu], [o=%#x, c=%d]\n",
+               fprintf(stderr, "bb=[%p,%" SIZE_T_FORMAT "u], %d [b=%p,%"
+                   SIZE_T_FORMAT "u], [o=%#x, c=%d]\n",
                    bb->fbuf, bb->flen, ms->offset, b->fbuf, b->flen,
                    m->offset, cont_level);
        }