diff options
author | fergus.henderson <fergus.henderson@01de4be4-8c4a-0410-9132-4925637da917> | 2008-07-30 02:28:41 +0000 |
---|---|---|
committer | fergus.henderson <fergus.henderson@01de4be4-8c4a-0410-9132-4925637da917> | 2008-07-30 02:28:41 +0000 |
commit | 2365d95ccfd74e4f62cea6a906cfd1bf543beb77 (patch) | |
tree | 143339f5e9a37c6cd5930e38c23e18c3c2815c82 | |
parent | 66b8e22f4576f3ca50ebbdfb1a5444c5e592a3a1 (diff) | |
download | distcc-2365d95ccfd74e4f62cea6a906cfd1bf543beb77.tar.gz |
Fix some warnings with -Wcast-align that show up only on machines
that don't support unaligned accesses.
Fix some const correctness warnings that show up only on machines
that don't have vsnprintf().
Reviewers: Craig Silverstein
git-svn-id: http://distcc.googlecode.com/svn/trunk@569 01de4be4-8c4a-0410-9132-4925637da917
-rw-r--r-- | src/fix_debug_info.c | 17 | ||||
-rw-r--r-- | src/netutil.c | 3 | ||||
-rw-r--r-- | src/snprintf.c | 17 | ||||
-rw-r--r-- | src/srvnet.c | 3 |
4 files changed, 22 insertions, 18 deletions
diff --git a/src/fix_debug_info.c b/src/fix_debug_info.c index 2c1da60..d529c4f 100644 --- a/src/fix_debug_info.c +++ b/src/fix_debug_info.c @@ -64,7 +64,8 @@ static int FindElfSection(const void *elf_mapped_base, off_t elf_size, const char *desired_section_name, const void **section_start, int *section_size) { const unsigned char *elf_base = (const unsigned char *) elf_mapped_base; - const Elf32_Ehdr *elf32_header = (const Elf32_Ehdr *) (elf_base); + /* The double cast below avoids warnings with -Wcast-align. */ + const Elf32_Ehdr *elf32_header = (const Elf32_Ehdr *) (const void *) elf_base; unsigned int i; unsigned int num_sections; @@ -128,7 +129,8 @@ static int FindElfSection(const void *elf_mapped_base, off_t elf_size, if (elf32_header->e_ident[EI_CLASS] == ELFCLASS32) { const Elf32_Ehdr *elf_header = elf32_header; const Elf32_Shdr *sections = - (const Elf32_Shdr *) (elf_base + elf_header->e_shoff); + /* The double cast below avoids warnings with -Wcast-align. */ + (const Elf32_Shdr *) (const void *) (elf_base + elf_header->e_shoff); const Elf32_Shdr *string_section = sections + elf_header->e_shstrndx; const Elf32_Shdr *desired_section = NULL; @@ -156,9 +158,9 @@ static int FindElfSection(const void *elf_mapped_base, off_t elf_size, num_sections = sections[0].sh_size; } for (i = 0; i < num_sections; ++i) { - const char *section_name = (char*)(elf_base + - string_section->sh_offset + - sections[i].sh_name); + const char *section_name = (char *)(elf_base + + string_section->sh_offset + + sections[i].sh_name); if (!strcmp(section_name, desired_section_name)) { desired_section = §ions[i]; break; @@ -173,9 +175,10 @@ static int FindElfSection(const void *elf_mapped_base, off_t elf_size, return 0; } } else if (elf32_header->e_ident[EI_CLASS] == ELFCLASS64) { - const Elf64_Ehdr *elf_header = (const Elf64_Ehdr *) elf_base; + /* The double cast below avoids warnings with -Wcast-align. */ + const Elf64_Ehdr *elf_header = (const Elf64_Ehdr *) (const void *) elf_base; const Elf64_Shdr *sections = - (const Elf64_Shdr *) (elf_base + elf_header->e_shoff); + (const Elf64_Shdr *) (const void *) (elf_base + elf_header->e_shoff); const Elf64_Shdr *string_section = sections + elf_header->e_shstrndx; const Elf64_Shdr *desired_section = NULL; diff --git a/src/netutil.c b/src/netutil.c index 6ad6711..7324750 100644 --- a/src/netutil.c +++ b/src/netutil.c @@ -197,7 +197,8 @@ int dcc_sockaddr_to_string(struct sockaddr *sa, *p_buf = strdup("NOTSOCKET"); return 0; } else if (sa->sa_family == AF_INET) { - struct sockaddr_in *sain = (struct sockaddr_in *) sa; + /* The double-cast here suppresses warnings from -Wcast-align. */ + struct sockaddr_in *sain = (struct sockaddr_in *) (void *) sa; asprintf(p_buf, "%s:%d", inet_ntoa(sain->sin_addr), ntohs(sain->sin_port)); diff --git a/src/snprintf.c b/src/snprintf.c index 9402422..da57960 100644 --- a/src/snprintf.c +++ b/src/snprintf.c @@ -154,7 +154,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in); static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, - char *value, int flags, int min, int max); + const char *value, int flags, int min, int max); static void fmtint(char *buffer, size_t *currlen, size_t maxlen, long value, int base, int min, int max, int flags); static void fmtfp(char *buffer, size_t *currlen, size_t maxlen, @@ -396,7 +396,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args break; case 's': strvalue = va_arg (args, char *); - const_strvalue = strvalue; + const_strvalue = strvalue; if (!const_strvalue) const_strvalue = "(NULL)"; if (max == -1) { max = strlen(const_strvalue); @@ -463,20 +463,19 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args } static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, - char *value, int flags, int min, int max) + const char *value, int flags, int min, int max) { int padlen, strln; /* amount to pad */ int cnt = 0; - const char* const_value = value; #ifdef DEBUG_SNPRINTF printf("fmtstr min=%d max=%d s=[%s]\n", min, max, value); #endif - if (const_value == 0) { - const_value = "<NULL>"; + if (value == 0) { + value = "<NULL>"; } - for (strln = 0; const_value[strln]; ++strln); /* strlen */ + for (strln = 0; value[strln]; ++strln); /* strlen */ padlen = min - strln; if (padlen < 0) padlen = 0; @@ -488,8 +487,8 @@ static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, --padlen; ++cnt; } - while (*const_value && (cnt < max)) { - dopr_outch (buffer, currlen, maxlen, *const_value++); + while (*value && (cnt < max)) { + dopr_outch (buffer, currlen, maxlen, *value++); ++cnt; } while ((padlen < 0) && (cnt < max)) { diff --git a/src/srvnet.c b/src/srvnet.c index 287ddbf..0039367 100644 --- a/src/srvnet.c +++ b/src/srvnet.c @@ -254,7 +254,8 @@ int dcc_check_client(struct sockaddr *psa, for (l = allowed; l; l = l->next) { if (psa->sa_family == AF_INET) { in_addr_t cli_inaddr; - cli_inaddr = ((struct sockaddr_in *) psa)->sin_addr.s_addr; + /* The double-cast here avoids warnings from -Wcast-align. */ + cli_inaddr = ((struct sockaddr_in *) (void *) psa)->sin_addr.s_addr; if ((ret = dcc_check_address(cli_inaddr, l->addr, l->mask)) == 0) break; |