From: Christos Zoulas Date: Mon, 17 Oct 2005 18:41:44 +0000 (+0000) Subject: void casts, problems with 64 bit elf files. X-Git-Tag: FILE5_05~791 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a3a7e43f2edd0794948b44546ae5b179b174b727;p=file void casts, problems with 64 bit elf files. --- diff --git a/src/file.c b/src/file.c index 019d754a..a482f637 100644 --- a/src/file.c +++ b/src/file.c @@ -71,7 +71,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: file.c,v 1.99 2005/10/17 17:39:39 christos Exp $") +FILE_RCSID("@(#)$Id: file.c,v 1.100 2005/10/17 18:41:44 christos Exp $") #endif /* lint */ @@ -159,7 +159,8 @@ main(int argc, char *argv[]) #endif #ifdef LC_CTYPE - setlocale(LC_CTYPE, ""); /* makes islower etc work for other langs */ + /* makes islower etc work for other langs */ + (void)setlocale(LC_CTYPE, ""); #endif #ifdef __EMX__ @@ -252,9 +253,9 @@ main(int argc, char *argv[]) flags |= MAGIC_DEVICES; break; case 'v': - (void) fprintf(stdout, "%s-%d.%.2d\n", progname, + (void)fprintf(stdout, "%s-%d.%.2d\n", progname, FILE_VERSION_MAJOR, patchlevel); - (void) fprintf(stdout, "magic file from %s\n", + (void)fprintf(stdout, "magic file from %s\n", magicfile); return 1; case 'z': @@ -322,6 +323,7 @@ main(int argc, char *argv[]) private void +/*ARGSUSED*/ load(const char *m, int flags) { if (magic) @@ -377,10 +379,10 @@ unwrap(char *fn) buf[len - 1] = '\0'; process(buf, wid); if(nobuffer) - (void) fflush(stdout); + (void)fflush(stdout); } - (void) fclose(f); + (void)fclose(f); } private void @@ -390,14 +392,14 @@ process(const char *inname, int wid) int std_in = strcmp(inname, "-") == 0; if (wid > 0 && !bflag) - (void) printf("%s%s%*s ", std_in ? "/dev/stdin" : inname, + (void)printf("%s%s%*s ", std_in ? "/dev/stdin" : inname, separator, (int) (nopad ? 0 : (wid - file_mbswidth(inname))), ""); type = magic_file(magic, std_in ? NULL : inname); if (type == NULL) - printf("ERROR: %s\n", magic_error(magic)); + (void)printf("ERROR: %s\n", magic_error(magic)); else - printf("%s\n", type); + (void)printf("%s\n", type); } @@ -506,7 +508,7 @@ usage(void) private void help(void) { - puts( + (void)puts( "Usage: file [OPTION]... [FILE]...\n" "Determine file type of FILEs.\n" "\n" diff --git a/src/funcs.c b/src/funcs.c index 63752e61..c4f8aa45 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -32,7 +32,7 @@ #include #ifndef lint -FILE_RCSID("@(#)$Id: funcs.c,v 1.15 2005/07/12 20:05:38 christos Exp $") +FILE_RCSID("@(#)$Id: funcs.c,v 1.16 2005/10/17 18:41:44 christos Exp $") #endif /* lint */ #ifndef HAVE_VSNPRINTF @@ -179,9 +179,9 @@ file_getbuffer(struct magic_set *ms) *np++ = *op; } else { *np++ = '\\'; - *np++ = ((*op >> 6) & 3) + '0'; - *np++ = ((*op >> 3) & 7) + '0'; - *np++ = ((*op >> 0) & 7) + '0'; + *np++ = (((uint32_t)*op >> 6) & 3) + '0'; + *np++ = (((uint32_t)*op >> 3) & 7) + '0'; + *np++ = (((uint32_t)*op >> 0) & 7) + '0'; } } *np = '\0'; diff --git a/src/readelf.c b/src/readelf.c index 7fa1a54f..8a61f0cd 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -37,7 +37,7 @@ #include "readelf.h" #ifndef lint -FILE_RCSID("@(#)$Id: readelf.c,v 1.51 2005/10/16 07:37:13 christos Exp $") +FILE_RCSID("@(#)$Id: readelf.c,v 1.52 2005/10/17 18:41:44 christos Exp $") #endif #ifdef ELFCORE @@ -129,10 +129,10 @@ getu64(int swap, uint64_t value) : sizeof sh64) #define xsh_size (class == ELFCLASS32 \ ? getu32(swap, sh32.sh_size) \ - : getu32(swap, sh64.sh_size)) + : getu64(swap, sh64.sh_size)) #define xsh_offset (class == ELFCLASS32 \ ? getu32(swap, sh32.sh_offset) \ - : getu32(swap, sh64.sh_offset)) + : getu64(swap, sh64.sh_offset)) #define xsh_type (class == ELFCLASS32 \ ? getu32(swap, sh32.sh_type) \ : getu32(swap, sh64.sh_type)) @@ -696,18 +696,19 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num, file_badread(ms); return -1; } - if ((nbuf = malloc(xsh_size)) == NULL) { + if ((nbuf = malloc((size_t)xsh_size)) == NULL) { file_error(ms, errno, "Cannot allocate memory" " for note"); return -1; } - if ((noff = lseek(fd, xsh_offset, SEEK_SET)) == + if ((noff = lseek(fd, (off_t)xsh_offset, SEEK_SET)) == (off_t)-1) { file_badread(ms); free(nbuf); return -1; } - if (read(fd, nbuf, xsh_size) != xsh_size) { + if (read(fd, nbuf, (size_t)xsh_size) != + (ssize_t)xsh_size) { free(nbuf); file_badread(ms); return -1; @@ -715,9 +716,9 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num, noff = 0; for (;;) { - if (noff >= xsh_size) + if (noff >= (size_t)xsh_size) break; - noff = donote(ms, nbuf, noff, + noff = donote(ms, nbuf, (size_t)noff, (size_t)xsh_size, class, swap, 4, &flags); if (noff == 0) diff --git a/src/softmagic.c b/src/softmagic.c index cba8bf76..1b4dbd3f 100644 --- a/src/softmagic.c +++ b/src/softmagic.c @@ -39,13 +39,13 @@ #ifndef lint -FILE_RCSID("@(#)$Id: softmagic.c,v 1.74 2005/07/29 17:57:20 christos Exp $") +FILE_RCSID("@(#)$Id: softmagic.c,v 1.75 2005/10/17 18:41:44 christos Exp $") #endif /* lint */ private int match(struct magic_set *, struct magic *, uint32_t, const unsigned char *, size_t); private int mget(struct magic_set *, union VALUETYPE *, const unsigned char *, - struct magic *, size_t, int); + struct magic *, size_t, unsigned int); private int mcheck(struct magic_set *, union VALUETYPE *, struct magic *); private int32_t mprint(struct magic_set *, union VALUETYPE *, struct magic *); private void mdebug(uint32_t, const char *, size_t); @@ -679,13 +679,14 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir, * might even cause problems */ if (nbytes < sizeof(*p)) - (void)memset(((char *)p) + nbytes, '\0', sizeof(*p) - nbytes); + (void)memset(((char *)(void *)p) + nbytes, '\0', + sizeof(*p) - nbytes); return 0; } private int mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s, - struct magic *m, size_t nbytes, int cont_level) + struct magic *m, size_t nbytes, unsigned int cont_level) { uint32_t offset = m->offset; @@ -701,7 +702,7 @@ mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s, int off = m->in_offset; if (m->in_op & FILE_OPINDIRECT) { const union VALUETYPE *q = - ((const union VALUETYPE *)(s + offset + off)); + ((const void *)(s + offset + off)); switch (m->in_type) { case FILE_BYTE: off = q->b;