From: Christos Zoulas Date: Wed, 16 Jul 2008 18:00:57 +0000 (+0000) Subject: make this compilable with a c++ compiler. X-Git-Tag: FILE4_26~21 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f931efcfd206219ac2a5a66b5e2b21e1ab30aff;p=file make this compilable with a c++ compiler. --- diff --git a/src/apprentice.c b/src/apprentice.c index 0f9a01a5..07189d3f 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -49,7 +49,7 @@ #include #ifndef lint -FILE_RCSID("@(#)$File: apprentice.c,v 1.136 2008/05/18 23:20:40 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.137 2008/07/02 15:22:47 christos Exp $") #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -297,7 +297,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action, return -1; } - if ((ml = malloc(sizeof(*ml))) == NULL) { + if ((ml = CAST(struct mlist *, malloc(sizeof(*ml)))) == NULL) { file_delmagic(magic, mapped, nmagic); file_oomem(ms, sizeof(*ml)); return -1; @@ -360,7 +360,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action) } fn = mfn; - if ((mlist = malloc(sizeof(*mlist))) == NULL) { + if ((mlist = CAST(struct mlist *, malloc(sizeof(*mlist)))) == NULL) { free(mfn); file_oomem(ms, sizeof(*mlist)); return NULL; @@ -525,8 +525,8 @@ apprentice_magic_strength(const struct magic *m) private int apprentice_sort(const void *a, const void *b) { - const struct magic_entry *ma = a; - const struct magic_entry *mb = b; + const struct magic_entry *ma = CAST(const struct magic_entry *, a); + const struct magic_entry *mb = CAST(const struct magic_entry *, b); size_t sa = apprentice_magic_strength(ma->mp); size_t sb = apprentice_magic_strength(mb->mp); if (sa == sb) @@ -676,6 +676,7 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, int errs = 0; struct magic_entry *marray; uint32_t marraycount, i, mentrycount = 0, starttest; + size_t slen; char subfn[MAXPATHLEN]; struct stat st; DIR *dir; @@ -684,7 +685,8 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, ms->flags |= MAGIC_CHECK; /* Enable checks for parsed files */ maxmagic = MAXMAGIS; - if ((marray = calloc(maxmagic, sizeof(*marray))) == NULL) { + if ((marray = CAST(struct magic_entry *, calloc(maxmagic, + sizeof(*marray)))) == NULL) { file_oomem(ms, maxmagic * sizeof(*marray)); return -1; } @@ -772,8 +774,9 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, for (i = 0; i < marraycount; i++) mentrycount += marray[i].cont_count; - if ((*magicp = malloc(sizeof(**magicp) * mentrycount)) == NULL) { - file_oomem(ms, sizeof(**magicp) * mentrycount); + slen = sizeof(**magicp) * mentrycount; + if ((*magicp = CAST(struct magic *, malloc(slen))) == NULL) { + file_oomem(ms, slen); errs++; goto out; } @@ -1061,7 +1064,8 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp, if (me->cont_count == me->max_count) { struct magic *nm; size_t cnt = me->max_count + ALLOC_CHUNK; - if ((nm = realloc(me->mp, sizeof(*nm) * cnt)) == NULL) { + if ((nm = CAST(struct magic *, realloc(me->mp, + sizeof(*nm) * cnt))) == NULL) { file_oomem(ms, sizeof(*nm) * cnt); return -1; } @@ -1076,7 +1080,8 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp, struct magic_entry *mp; maxmagic += ALLOC_INCR; - if ((mp = realloc(*mentryp, sizeof(*mp) * maxmagic)) == + if ((mp = CAST(struct magic_entry *, + realloc(*mentryp, sizeof(*mp) * maxmagic))) == NULL) { file_oomem(ms, sizeof(*mp) * maxmagic); return -1; @@ -1087,8 +1092,9 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp, } me = &(*mentryp)[*nmentryp]; if (me->mp == NULL) { - if ((m = malloc(sizeof(*m) * ALLOC_CHUNK)) == NULL) { - file_oomem(ms, sizeof(*m) * ALLOC_CHUNK); + size_t len = sizeof(*m) * ALLOC_CHUNK; + if ((m = CAST(struct magic *, malloc(len))) == NULL) { + file_oomem(ms, len); return -1; } me->mp = m; @@ -2025,7 +2031,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, } #define RET 2 #else - if ((mm = malloc((size_t)st.st_size)) == NULL) { + if ((mm = CAST(void *, malloc((size_t)st.st_size))) == NULL) { file_oomem(ms, (size_t)st.st_size); goto error1; } @@ -2035,7 +2041,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp, } #define RET 1 #endif - *magicp = mm; + *magicp = CAST(struct magic *, mm); (void)close(fd); fd = -1; ptr = (uint32_t *)(void *)*magicp; diff --git a/src/ascmagic.c b/src/ascmagic.c index 75ed43bb..63e71aec 100644 --- a/src/ascmagic.c +++ b/src/ascmagic.c @@ -49,7 +49,7 @@ #include "names.h" #ifndef lint -FILE_RCSID("@(#)$File: ascmagic.c,v 1.62 2008/03/01 22:21:48 rrt Exp $") +FILE_RCSID("@(#)$File: ascmagic.c,v 1.63 2008/05/09 14:20:28 christos Exp $") #endif /* lint */ #define MAXLINELEN 300 /* longest sane line length */ @@ -103,9 +103,11 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes) while (nbytes > 1 && buf[nbytes - 1] == '\0') nbytes--; - if ((nbuf = calloc(1, (nbytes + 1) * sizeof(nbuf[0]))) == NULL) + if ((nbuf = CAST(unsigned char *, calloc((size_t)1, + (nbytes + 1) * sizeof(nbuf[0])))) == NULL) goto done; - if ((ubuf = calloc(1, (nbytes + 1) * sizeof(ubuf[0]))) == NULL) + if ((ubuf = CAST(unichar *, calloc((size_t)1, + (nbytes + 1) * sizeof(ubuf[0])))) == NULL) goto done; /* @@ -171,7 +173,7 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes) re-converting improved, or at least realloced after re-converting conversion. */ mlen = ulen * 6; - if ((utf8_buf = malloc(mlen)) == NULL) { + if ((utf8_buf = CAST(unsigned char *, malloc(mlen))) == NULL) { file_oomem(ms, mlen); goto done; } diff --git a/src/compress.c b/src/compress.c index 9b41e1df..9d2311b6 100644 --- a/src/compress.c +++ b/src/compress.c @@ -56,7 +56,7 @@ #ifndef lint -FILE_RCSID("@(#)$File: compress.c,v 1.55 2008/01/26 18:45:16 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.56 2008/02/07 00:58:52 christos Exp $") #endif private const struct { @@ -330,7 +330,7 @@ uncompressgzipped(struct magic_set *ms, const unsigned char *old, if (data_start >= n) return 0; - if ((*newch = (unsigned char *)malloc(HOWMANY + 1)) == NULL) { + if ((*newch = CAST(unsigned char *, malloc(HOWMANY + 1))) == NULL) { return 0; } diff --git a/src/elfclass.h b/src/elfclass.h index 91a0e5c9..27817d0f 100644 --- a/src/elfclass.h +++ b/src/elfclass.h @@ -35,7 +35,7 @@ switch (type) { #ifdef ELFCORE case ET_CORE: - if (dophn_core(ms, class, swap, fd, + if (dophn_core(ms, clazz, swap, fd, (off_t)elf_getu(swap, elfhdr.e_phoff), elf_getu16(swap, elfhdr.e_phnum), (size_t)elf_getu16(swap, elfhdr.e_phentsize), @@ -45,7 +45,7 @@ #endif case ET_EXEC: case ET_DYN: - if (dophn_exec(ms, class, swap, fd, + if (dophn_exec(ms, clazz, swap, fd, (off_t)elf_getu(swap, elfhdr.e_phoff), elf_getu16(swap, elfhdr.e_phnum), (size_t)elf_getu16(swap, elfhdr.e_phentsize), @@ -54,7 +54,7 @@ return -1; /*FALLTHROUGH*/ case ET_REL: - if (doshn(ms, class, swap, fd, + if (doshn(ms, clazz, swap, fd, (off_t)elf_getu(swap, elfhdr.e_shoff), elf_getu16(swap, elfhdr.e_shnum), (size_t)elf_getu16(swap, elfhdr.e_shentsize), diff --git a/src/file.h b/src/file.h index bbad83a2..1e77ee00 100644 --- a/src/file.h +++ b/src/file.h @@ -27,7 +27,7 @@ */ /* * file.h - definitions for file(1) program - * @(#)$File: file.h,v 1.106 2008/07/02 15:22:47 christos Exp $ + * @(#)$File: file.h,v 1.107 2008/07/15 17:45:13 christos Exp $ */ #ifndef __file_h__ @@ -110,6 +110,20 @@ #define FILE_CHECK 1 #define FILE_COMPILE 2 +union VALUETYPE { + uint8_t b; + uint16_t h; + uint32_t l; + uint64_t q; + uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */ + uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */ + uint8_t hq[8]; /* 8 bytes of a fixed-endian "quad" */ + char s[MAXstring]; /* the search string or regex pattern */ + unsigned char us[MAXstring]; + float f; + double d; +}; + struct magic { /* Word 1 */ uint16_t cont_level; /* level of ">" */ @@ -242,21 +256,8 @@ struct magic { #define num_mask _u._mask #define str_range _u._s._count #define str_flags _u._s._flags - /* Words 9-16 */ - union VALUETYPE { - uint8_t b; - uint16_t h; - uint32_t l; - uint64_t q; - uint8_t hs[2]; /* 2 bytes of a fixed-endian "short" */ - uint8_t hl[4]; /* 4 bytes of a fixed-endian "long" */ - uint8_t hq[8]; /* 8 bytes of a fixed-endian "quad" */ - char s[MAXstring]; /* the search string or regex pattern */ - unsigned char us[MAXstring]; - float f; - double d; - } value; /* either number or string */ + union VALUETYPE value; /* either number or string */ /* Words 17..31 */ char desc[MAXDESC]; /* description */ /* Words 32..47 */ @@ -288,18 +289,25 @@ struct mlist { struct mlist *next, *prev; }; +#ifdef __cplusplus +#define CAST(T, b) static_cast(b) +#else +#define CAST(T, b) (b) +#endif + +struct level_info { + int32_t off; + int got_match; +#ifdef ENABLE_CONDITIONALS + int last_match; + int last_cond; /* used for error checking by parse() */ +#endif +} *li; struct magic_set { struct mlist *mlist; struct cont { size_t len; - struct level_info { - int32_t off; - int got_match; -#ifdef ENABLE_CONDITIONALS - int last_match; - int last_cond; /* used for error checking by parse() */ -#endif - } *li; + struct level_info *li; } c; struct out { char *buf; /* Accumulation buffer */ @@ -397,6 +405,7 @@ int asprintf(char **ptr, const char *format_string, ...); #define O_BINARY 0 #endif +#ifndef __cplusplus #ifdef __GNUC__ static const char *rcsid(const char *) __attribute__((__used__)); #endif @@ -404,5 +413,8 @@ static const char *rcsid(const char *) __attribute__((__used__)); static const char *rcsid(const char *p) { \ return rcsid(p = id); \ } +#else +#define FILE_RCSID(id) +#endif #endif /* __file_h__ */ diff --git a/src/funcs.c b/src/funcs.c index 5a044afd..c1b45e4a 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -41,7 +41,7 @@ #endif #ifndef lint -FILE_RCSID("@(#)$File: funcs.c,v 1.42 2008/07/03 15:48:18 christos Exp $") +FILE_RCSID("@(#)$File: funcs.c,v 1.43 2008/07/03 15:53:10 christos Exp $") #endif /* lint */ #ifndef SIZE_MAX @@ -159,6 +159,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname, const void *buf, { int m; int mime = ms->flags & MAGIC_MIME; + const unsigned char *ubuf = CAST(const unsigned char *, buf); if (nb == 0) { if ((!mime || (mime & MAGIC_MIME_TYPE)) && @@ -189,16 +190,16 @@ file_buffer(struct magic_set *ms, int fd, const char *inname, const void *buf, /* try compression stuff */ if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) != 0 || - (m = file_zmagic(ms, fd, inname, buf, nb)) == 0) { + (m = file_zmagic(ms, fd, inname, ubuf, nb)) == 0) { /* Check if we have a tar file */ if ((ms->flags & MAGIC_NO_CHECK_TAR) != 0 || - (m = file_is_tar(ms, buf, nb)) == 0) { + (m = file_is_tar(ms, ubuf, nb)) == 0) { /* try tests in /etc/magic (or surrogate magic file) */ if ((ms->flags & MAGIC_NO_CHECK_SOFT) != 0 || - (m = file_softmagic(ms, buf, nb, BINTEST)) == 0) { + (m = file_softmagic(ms, ubuf, nb, BINTEST)) == 0) { /* try known keywords, check whether it is ASCII */ if ((ms->flags & MAGIC_NO_CHECK_ASCII) != 0 || - (m = file_ascmagic(ms, buf, nb)) == 0) { + (m = file_ascmagic(ms, ubuf, nb)) == 0) { /* abandon hope, all ye who remain here */ if ((!mime || (mime & MAGIC_MIME_TYPE)) && file_printf(ms, mime ? "application/octet-stream" : @@ -220,7 +221,7 @@ file_buffer(struct magic_set *ms, int fd, const char *inname, const void *buf, * information from the ELF headers that cannot easily * be extracted with rules in the magic file. */ - (void)file_tryelf(ms, fd, buf, nb); + (void)file_tryelf(ms, fd, ubuf, nb); } #endif return m; @@ -267,7 +268,7 @@ file_getbuffer(struct magic_set *ms) return NULL; } psize = len * 4 + 1; - if ((pbuf = realloc(ms->o.pbuf, psize)) == NULL) { + if ((pbuf = CAST(char *, realloc(ms->o.pbuf, psize))) == NULL) { file_oomem(ms, psize); return NULL; } @@ -330,8 +331,9 @@ file_check_mem(struct magic_set *ms, unsigned int level) if (level >= ms->c.len) { len = (ms->c.len += 20) * sizeof(*ms->c.li); - ms->c.li = (ms->c.li == NULL) ? malloc(len) : - realloc(ms->c.li, len); + ms->c.li = CAST(struct level_info *, (ms->c.li == NULL) ? + malloc(len) : + realloc(ms->c.li, len)); if (ms->c.li == NULL) { file_oomem(ms, len); return -1; diff --git a/src/magic.c b/src/magic.c index e23f7c2a..81320f99 100644 --- a/src/magic.c +++ b/src/magic.c @@ -65,7 +65,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$File: magic.c,v 1.51 2008/05/16 14:25:01 christos Exp $") +FILE_RCSID("@(#)$File: magic.c,v 1.52 2008/07/03 15:53:10 christos Exp $") #endif /* lint */ #ifndef PIPE_BUF @@ -99,8 +99,10 @@ public struct magic_set * magic_open(int flags) { struct magic_set *ms; + size_t len; - if ((ms = calloc((size_t)1, sizeof(struct magic_set))) == NULL) + if ((ms = CAST(magic_set *, calloc((size_t)1, + sizeof(struct magic_set)))) == NULL) return NULL; if (magic_setflags(ms, flags) == -1) { @@ -109,9 +111,9 @@ magic_open(int flags) } ms->o.buf = ms->o.pbuf = NULL; + len = (ms->c.len = 10) * sizeof(*ms->c.li); - ms->c.li = malloc((ms->c.len = 10) * sizeof(*ms->c.li)); - if (ms->c.li == NULL) + if ((ms->c.li = CAST(struct level_info *, malloc(len))) == NULL) goto free; ms->haderr = 0; @@ -269,7 +271,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) * some overlapping space for matches near EOF */ #define SLOP (1 + sizeof(union VALUETYPE)) - if ((buf = malloc(HOWMANY + SLOP)) == NULL) + if ((buf = CAST(unsigned char *, malloc(HOWMANY + SLOP))) == NULL) return NULL; if (file_reset(ms) == -1) diff --git a/src/readelf.c b/src/readelf.c index 3e492932..9493347b 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -38,7 +38,7 @@ #include "magic.h" #ifndef lint -FILE_RCSID("@(#)$File: readelf.c,v 1.74 2008/05/28 21:02:29 christos Exp $") +FILE_RCSID("@(#)$File: readelf.c,v 1.75 2008/06/05 12:59:15 christos Exp $") #endif #ifdef ELFCORE @@ -49,7 +49,7 @@ private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t, off_t, int *, int); private int doshn(struct magic_set *, int, int, int, off_t, int, size_t, int *, int); -private size_t donote(struct magic_set *, unsigned char *, size_t, size_t, int, +private size_t donote(struct magic_set *, void *, size_t, size_t, int, int, size_t, int *); #define ELF_ALIGN(a) ((((a) + align - 1) / align) * align) @@ -135,72 +135,72 @@ getu64(int swap, uint64_t value) # define elf_getu64(swap, value) getu64(swap, value) #endif -#define xsh_addr (class == ELFCLASS32 \ +#define xsh_addr (clazz == ELFCLASS32 \ ? (void *) &sh32 \ : (void *) &sh64) -#define xsh_sizeof (class == ELFCLASS32 \ +#define xsh_sizeof (clazz == ELFCLASS32 \ ? sizeof sh32 \ : sizeof sh64) -#define xsh_size (class == ELFCLASS32 \ +#define xsh_size (clazz == ELFCLASS32 \ ? elf_getu32(swap, sh32.sh_size) \ : elf_getu64(swap, sh64.sh_size)) -#define xsh_offset (class == ELFCLASS32 \ +#define xsh_offset (clazz == ELFCLASS32 \ ? elf_getu32(swap, sh32.sh_offset) \ : elf_getu64(swap, sh64.sh_offset)) -#define xsh_type (class == ELFCLASS32 \ +#define xsh_type (clazz == ELFCLASS32 \ ? elf_getu32(swap, sh32.sh_type) \ : elf_getu32(swap, sh64.sh_type)) -#define xph_addr (class == ELFCLASS32 \ +#define xph_addr (clazz == ELFCLASS32 \ ? (void *) &ph32 \ : (void *) &ph64) -#define xph_sizeof (class == ELFCLASS32 \ +#define xph_sizeof (clazz == ELFCLASS32 \ ? sizeof ph32 \ : sizeof ph64) -#define xph_type (class == ELFCLASS32 \ +#define xph_type (clazz == ELFCLASS32 \ ? elf_getu32(swap, ph32.p_type) \ : elf_getu32(swap, ph64.p_type)) -#define xph_offset (off_t)(class == ELFCLASS32 \ +#define xph_offset (off_t)(clazz == ELFCLASS32 \ ? elf_getu32(swap, ph32.p_offset) \ : elf_getu64(swap, ph64.p_offset)) -#define xph_align (size_t)((class == ELFCLASS32 \ +#define xph_align (size_t)((clazz == ELFCLASS32 \ ? (off_t) (ph32.p_align ? \ elf_getu32(swap, ph32.p_align) : 4) \ : (off_t) (ph64.p_align ? \ elf_getu64(swap, ph64.p_align) : 4))) -#define xph_filesz (size_t)((class == ELFCLASS32 \ +#define xph_filesz (size_t)((clazz == ELFCLASS32 \ ? elf_getu32(swap, ph32.p_filesz) \ : elf_getu64(swap, ph64.p_filesz))) -#define xnh_addr (class == ELFCLASS32 \ +#define xnh_addr (clazz == ELFCLASS32 \ ? (void *) &nh32 \ : (void *) &nh64) -#define xph_memsz (size_t)((class == ELFCLASS32 \ +#define xph_memsz (size_t)((clazz == ELFCLASS32 \ ? elf_getu32(swap, ph32.p_memsz) \ : elf_getu64(swap, ph64.p_memsz))) -#define xnh_sizeof (class == ELFCLASS32 \ +#define xnh_sizeof (clazz == ELFCLASS32 \ ? sizeof nh32 \ : sizeof nh64) -#define xnh_type (class == ELFCLASS32 \ +#define xnh_type (clazz == ELFCLASS32 \ ? elf_getu32(swap, nh32.n_type) \ : elf_getu32(swap, nh64.n_type)) -#define xnh_namesz (class == ELFCLASS32 \ +#define xnh_namesz (clazz == ELFCLASS32 \ ? elf_getu32(swap, nh32.n_namesz) \ : elf_getu32(swap, nh64.n_namesz)) -#define xnh_descsz (class == ELFCLASS32 \ +#define xnh_descsz (clazz == ELFCLASS32 \ ? elf_getu32(swap, nh32.n_descsz) \ : elf_getu32(swap, nh64.n_descsz)) -#define prpsoffsets(i) (class == ELFCLASS32 \ +#define prpsoffsets(i) (clazz == ELFCLASS32 \ ? prpsoffsets32[i] \ : prpsoffsets64[i]) -#define xcap_addr (class == ELFCLASS32 \ +#define xcap_addr (clazz == ELFCLASS32 \ ? (void *) &cap32 \ : (void *) &cap64) -#define xcap_sizeof (class == ELFCLASS32 \ +#define xcap_sizeof (clazz == ELFCLASS32 \ ? sizeof cap32 \ : sizeof cap64) -#define xcap_tag (class == ELFCLASS32 \ +#define xcap_tag (clazz == ELFCLASS32 \ ? elf_getu32(swap, cap32.c_tag) \ : elf_getu64(swap, cap64.c_tag)) -#define xcap_val (class == ELFCLASS32 \ +#define xcap_val (clazz == ELFCLASS32 \ ? elf_getu32(swap, cap32.c_un.c_val) \ : elf_getu64(swap, cap64.c_un.c_val)) @@ -242,7 +242,7 @@ static const size_t prpsoffsets64[] = { #define NOFFSETS32 (sizeof prpsoffsets32 / sizeof prpsoffsets32[0]) #define NOFFSETS64 (sizeof prpsoffsets64 / sizeof prpsoffsets64[0]) -#define NOFFSETS (class == ELFCLASS32 ? NOFFSETS32 : NOFFSETS64) +#define NOFFSETS (clazz == ELFCLASS32 ? NOFFSETS32 : NOFFSETS64) /* * Look through the program headers of an executable image, searching @@ -288,7 +288,7 @@ private const char os_style_names[][8] = { #define FLAGS_DID_CORE_STYLE 4 private int -dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off, +dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, size_t size, off_t fsize, int *flags) { Elf32_Phdr ph32; @@ -353,7 +353,7 @@ dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off, if (offset >= (size_t)bufsize) break; offset = donote(ms, nbuf, offset, (size_t)bufsize, - class, swap, 4, flags); + clazz, swap, 4, flags); if (offset == 0) break; @@ -364,8 +364,8 @@ dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off, #endif private size_t -donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size, - int class, int swap, size_t align, int *flags) +donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size, + int clazz, int swap, size_t align, int *flags) { Elf32_Nhdr nh32; Elf64_Nhdr nh64; @@ -374,6 +374,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size, int os_style = -1; #endif uint32_t namesz, descsz; + unsigned char *nbuf = CAST(unsigned char *, vbuf); (void)memcpy(xnh_addr, &nbuf[offset], xnh_sizeof); offset += xnh_sizeof; @@ -814,7 +815,7 @@ static const cap_desc_t cap_desc_386[] = { }; private int -doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num, +doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, size_t size, int *flags, int mach) { Elf32_Shdr sh32; @@ -877,7 +878,7 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num, if (noff >= (size_t)xsh_size) break; noff = donote(ms, nbuf, (size_t)noff, - (size_t)xsh_size, class, swap, 4, + (size_t)xsh_size, clazz, swap, 4, flags); if (noff == 0) break; @@ -1007,7 +1008,7 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num, * otherwise it's statically linked. */ private int -dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off, +dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, size_t size, off_t fsize, int *flags, int sh_num) { Elf32_Phdr ph32; @@ -1099,7 +1100,7 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off, if (offset >= (size_t)bufsize) break; offset = donote(ms, nbuf, offset, - (size_t)bufsize, class, swap, align, + (size_t)bufsize, clazz, swap, align, flags); if (offset == 0) break; @@ -1128,7 +1129,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf, int32_t l; char c[sizeof (int32_t)]; } u; - int class; + int clazz; int swap; struct stat st; off_t fsize; @@ -1163,9 +1164,9 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf, } fsize = st.st_size; - class = buf[EI_CLASS]; + clazz = buf[EI_CLASS]; - switch (class) { + switch (clazz) { case ELFCLASS32: #undef elf_getu #define elf_getu(a, b) elf_getu32(a, b) @@ -1179,7 +1180,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf, #define elfhdr elf64hdr #include "elfclass.h" default: - if (file_printf(ms, ", unknown class %d", class) == -1) + if (file_printf(ms, ", unknown class %d", clazz) == -1) return -1; break; } diff --git a/src/softmagic.c b/src/softmagic.c index 08c49e68..64de03e9 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -38,7 +38,7 @@ #ifndef lint -FILE_RCSID("@(#)$File: softmagic.c,v 1.116 2008/02/25 02:54:08 rrt Exp $") +FILE_RCSID("@(#)$File: softmagic.c,v 1.117 2008/03/01 22:21:49 rrt Exp $") #endif /* lint */ private int match(struct magic_set *, struct magic *, uint32_t, @@ -906,8 +906,8 @@ mget(struct magic_set *ms, const unsigned char *s, if (m->flag & INDIR) { int off = m->in_offset; if (m->in_op & FILE_OPINDIRECT) { - const union VALUETYPE *q = - ((const void *)(s + offset + off)); + const union VALUETYPE *q = CAST(const union VALUETYPE *, + ((const void *)(s + offset + off))); switch (m->in_type) { case FILE_BYTE: off = q->b;