From 09c12ff0b54d493a4a823fa2836fdf286f991b95 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Fri, 10 Feb 2017 18:14:01 +0000 Subject: more cast stuff. --- src/apprentice.c | 8 +++++--- src/cdf.c | 10 ++++++---- src/compress.c | 10 +++++----- src/der.c | 10 +++++----- src/print.c | 4 ++-- src/readelf.c | 4 ++-- src/softmagic.c | 7 +++---- 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/apprentice.c b/src/apprentice.c index 0df97ba4..9262ff3d 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: apprentice.c,v 1.257 2017/02/04 16:46:16 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.258 2017/02/10 18:14:01 christos Exp $") #endif /* lint */ #include "magic.h" @@ -549,8 +549,10 @@ apprentice_unmap(struct magic_map *map) break; case MAP_TYPE_MALLOC: for (i = 0; i < MAGIC_SETS; i++) { - if ((char *)map->magic[i] >= (char *)map->p && - (char *)map->magic[i] <= (char *)map->p + map->len) + void *b = map->magic[i]; + void *p = map->p; + if (CAST(char *, b) >= CAST(char *, p) && + CAST(char *, b) <= CAST(char *, p) + map->len) continue; free(map->magic[i]); } diff --git a/src/cdf.c b/src/cdf.c index 47470b77..7909c818 100644 --- a/src/cdf.c +++ b/src/cdf.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: cdf.c,v 1.88 2017/02/07 23:21:29 christos Exp $") +FILE_RCSID("@(#)$File: cdf.c,v 1.89 2017/02/10 18:14:01 christos Exp $") #endif #include @@ -811,7 +811,7 @@ cdf_find_stream(const cdf_dir_t *dir, const char *name, int type) == 0) break; if (i > 0) - return i; + return CAST(int, i); DPRINTF(("Cannot find type %d `%s'\n", type, name)); errno = ESRCH; @@ -1068,7 +1068,7 @@ cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst, { size_t ss = cdf_check_stream(sst, h); const char *b = CAST(const char *, sst->sst_tab); - const char *eb = b + ss * sst->sst_len; + const char *nb, *eb = b + ss * sst->sst_len; size_t nr, i, j, k; cdf_catalog_entry_t *ce; uint16_t reclen; @@ -1113,7 +1113,9 @@ cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst, cep->ce_namlen = rlen; np = CAST(const uint16_t *, CAST(const void *, (b + 16))); - if (RCAST(const char *, np + cep->ce_namlen) > eb) { + nb = CAST(const char *, CAST(const void *, + (np + cep->ce_namlen))); + if (nb > eb) { cep->ce_namlen = 0; break; } diff --git a/src/compress.c b/src/compress.c index 687b5fa2..fce28507 100644 --- a/src/compress.c +++ b/src/compress.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: compress.c,v 1.101 2017/01/18 16:33:57 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.102 2017/02/10 18:14:01 christos Exp $") #endif #include "magic.h" @@ -94,7 +94,7 @@ static int zlibcmp(const unsigned char *buf) { unsigned short x = 1; - unsigned char *s = (unsigned char *)&x; + unsigned char *s = CCAST(unsigned char *, &x); if ((buf[0] & 0xf) != 8 || (buf[0] & 0x80) != 0) return 0; @@ -498,7 +498,7 @@ uncompresszlib(const unsigned char *old, unsigned char **newch, z.next_in = CCAST(Bytef *, old); z.avail_in = CAST(uint32_t, *n); z.next_out = *newch; - z.avail_out = bytes_max; + z.avail_out = CAST(unsigned int, bytes_max); z.zalloc = Z_NULL; z.zfree = Z_NULL; z.opaque = Z_NULL; @@ -633,7 +633,7 @@ filter_error(unsigned char *ubuf, ssize_t n) while (isspace((unsigned char)*p)) p++; n = strlen(p); - memmove(ubuf, p, n + 1); + memmove(ubuf, p, CAST(size_t, n + 1)); } DPRINTF("Filter error after[[[%s]]]\n", (char *)ubuf); if (islower(*ubuf)) @@ -689,7 +689,7 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old, } for (i = 0; i < __arraycount(fdp); i++) - copydesc(i, fdp[i]); + copydesc(CAST(int, i), fdp[i]); (void)execvp(compr[method].argv[0], (char *const *)(intptr_t)compr[method].argv); diff --git a/src/der.c b/src/der.c index 40dd1c5e..4e22caf4 100644 --- a/src/der.c +++ b/src/der.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: der.c,v 1.11 2016/11/07 15:51:23 christos Exp $") +FILE_RCSID("@(#)$File: der.c,v 1.12 2017/02/10 18:14:01 christos Exp $") #endif #endif @@ -201,7 +201,7 @@ getlength(const uint8_t *c, size_t *p, size_t l) if (*p + len >= l) return DER_BAD; - return len; + return CAST(uint32_t, len); } static const char * @@ -260,12 +260,12 @@ der_offs(struct magic_set *ms, struct magic *m, size_t nbytes) #endif if (m->cont_level != 0) { if (offs + tlen > nbytes) - return DER_BAD; - ms->c.li[m->cont_level - 1].off = offs + tlen; + return -1; + ms->c.li[m->cont_level - 1].off = CAST(int, offs + tlen); DPRINTF(("cont_level[%u] = %u\n", m->cont_level - 1, ms->c.li[m->cont_level - 1].off)); } - return offs; + return CAST(int32_t, offs); } int diff --git a/src/print.c b/src/print.c index a0221b12..0b918636 100644 --- a/src/print.c +++ b/src/print.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: print.c,v 1.81 2016/01/19 15:09:03 christos Exp $") +FILE_RCSID("@(#)$File: print.c,v 1.82 2017/02/10 18:14:01 christos Exp $") #endif /* lint */ #include @@ -238,7 +238,7 @@ file_fmttime(uint64_t v, int flags, char *buf) if (flags & FILE_T_WINDOWS) { struct timespec ts; - cdf_timestamp_to_timespec(&ts, v); + cdf_timestamp_to_timespec(&ts, CAST(cdf_timestamp_t, v)); t = ts.tv_sec; } else { // XXX: perhaps detect and print something if overflow diff --git a/src/readelf.c b/src/readelf.c index 6738942d..8898bd02 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -27,7 +27,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: readelf.c,v 1.130 2017/01/29 19:34:24 christos Exp $") +FILE_RCSID("@(#)$File: readelf.c,v 1.131 2017/02/10 18:14:01 christos Exp $") #endif #ifdef BUILTIN_ELF @@ -890,7 +890,7 @@ get_string_on_virtaddr(struct magic_set *ms, offset = get_offset_from_virtaddr(ms, swap, clazz, fd, ph_off, ph_num, fsize, virtaddr); - if ((buflen = pread(fd, buf, buflen, offset)) <= 0) { + if ((buflen = pread(fd, buf, CAST(size_t, buflen), offset)) <= 0) { file_badread(ms); return 0; } diff --git a/src/softmagic.c b/src/softmagic.c index 358a768c..6198eb29 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: softmagic.c,v 1.243 2017/02/07 23:27:32 christos Exp $") +FILE_RCSID("@(#)$File: softmagic.c,v 1.244 2017/02/10 18:14:01 christos Exp $") #endif /* lint */ #include "magic.h" @@ -1017,9 +1017,8 @@ private int mconvert(struct magic_set *ms, struct magic *m, int flip) { union VALUETYPE *p = &ms->ms_value; - uint8_t type; - switch (type = cvt_flip(m->type, flip)) { + switch (cvt_flip(m->type, flip)) { case FILE_BYTE: if (cvt_8(p, m) == -1) goto out; @@ -1184,7 +1183,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, case FILE_DER: case FILE_SEARCH: if (offset > nbytes) - offset = nbytes; + offset = CAST(uint32_t, nbytes); ms->search.s = RCAST(const char *, s) + offset; ms->search.s_len = nbytes - offset; ms->search.offset = offset; -- cgit v1.2.1