From bd3484fa6b8d04b1f836efdbf6c80f4d47cf1914 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 11 Apr 2009 15:52:32 +0200 Subject: [PATCH] Build code with -Wcast-qual, -Wcast-align and -Wsign-compare. --HG-- extra : convert_revision : d489ad995bb69850cba5a352f3ac85b74a54b5cf --- bin/xbps-repo/index.c | 2 +- bin/xbps-repo/util.c | 4 ++-- include/xbps_api.h | 7 ++++++- lib/cmpver.c | 2 +- lib/fexec.c | 2 +- lib/humanize_number.c | 2 +- lib/requiredby.c | 2 +- lib/sha256.c | 4 ++-- vars.mk | 1 + 9 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bin/xbps-repo/index.c b/bin/xbps-repo/index.c index b58fcae98bf..ba715cc1e1f 100644 --- a/bin/xbps-repo/index.c +++ b/bin/xbps-repo/index.c @@ -207,7 +207,7 @@ repoidx_addpkg(const char *file, const char *filename, const char *pkgdir) break; } prop_dictionary_set_uint64(newpkgd, "filename-size", - st.st_size); + (uint64_t)st.st_size); /* * Add dictionary into the index and update package count. */ diff --git a/bin/xbps-repo/util.c b/bin/xbps-repo/util.c index 29ca318b2cb..4772109211d 100644 --- a/bin/xbps-repo/util.c +++ b/bin/xbps-repo/util.c @@ -118,7 +118,7 @@ show_pkg_info(prop_dictionary_t dict) printf("Configuration files:\n"); sep = " "; (void)xbps_callback_array_iter_in_dict(dict, "conf_files", - list_strings_sep_in_array, (void *)sep); + list_strings_sep_in_array, __UNCONST(sep)); printf("\n"); } @@ -127,7 +127,7 @@ show_pkg_info(prop_dictionary_t dict) printf("Permanent directories:\n"); sep = " "; (void)xbps_callback_array_iter_in_dict(dict, "keep_dirs", - list_strings_sep_in_array, (void *)sep); + list_strings_sep_in_array, __UNCONST(sep)); printf("\n"); } diff --git a/include/xbps_api.h b/include/xbps_api.h index 27c63a8f73b..78a1d18389e 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -61,6 +61,10 @@ #define ARCHIVE_READ_BLOCKSIZE 2048 +#ifndef __UNCONST +#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) +#endif + /* from lib/cmpver.c */ int xbps_cmpver_packages(const char *, const char *); int xbps_cmpver_versions(const char *, const char *); @@ -105,7 +109,8 @@ bool xbps_add_obj_to_dict(prop_dictionary_t, prop_object_t, bool xbps_add_obj_to_array(prop_array_t, prop_object_t); int xbps_callback_array_iter_in_dict(prop_dictionary_t, - const char *, int (*fn)(prop_object_t, void *, bool *), + const char *, + int (*fn)(prop_object_t, void *, bool *), void *); int xbps_callback_array_iter_in_repolist(int (*fn)(prop_object_t, void *, bool *), void *); diff --git a/lib/cmpver.c b/lib/cmpver.c index a8f17d55bf4..e3874332a4f 100644 --- a/lib/cmpver.c +++ b/lib/cmpver.c @@ -241,7 +241,7 @@ xbps_cmpver_packages(const char *pkg1, const char *pkg2) /* Shortcut check for equality before invoking the parsing routines. */ if (result == 0 && (ve1 - v1 != ve2 - v2 || - strncasecmp(v1, v2, ve1 - v1) != 0)) { + strncasecmp(v1, v2, (size_t)ve1 - (size_t)v1) != 0)) { /* Loop over different components (the parts separated by dots). * If any component differs, we have the basis for an inequality. */ while(result == 0 && (v1 < ve1 || v2 < ve2)) { diff --git a/lib/fexec.c b/lib/fexec.c index 5b7f1c46d6f..c2595ec2033 100644 --- a/lib/fexec.c +++ b/lib/fexec.c @@ -70,7 +70,7 @@ pfcexec(const char *path, const char *file, const char **argv) _exit(127); } } - (void)execvp(file, (char ** const)argv); + (void)execvp(file, (char ** const)__UNCONST(argv)); _exit(127); /* NOTREACHED */ case -1: diff --git a/lib/humanize_number.c b/lib/humanize_number.c index 676689d28be..5e3dc19a1a0 100644 --- a/lib/humanize_number.c +++ b/lib/humanize_number.c @@ -106,7 +106,7 @@ xbps_humanize_number(char *buf, size_t len, int64_t bytes, if (scale & (HN_AUTOSCALE | HN_GETSCALE)) { /* See if there is additional columns can be used. */ - for (max = 100, i = len - baselen; i-- > 0;) + for (max = 100, i = (int)(len - baselen); i-- > 0;) max *= 10; /* diff --git a/lib/requiredby.c b/lib/requiredby.c index 19fd87ea219..1b7304aacb2 100644 --- a/lib/requiredby.c +++ b/lib/requiredby.c @@ -140,7 +140,7 @@ xbps_requiredby_pkg_remove(const char *pkgname) } rv = xbps_callback_array_iter_in_dict(dict, "packages", - remove_pkg_from_reqby, (void *)pkgname); + remove_pkg_from_reqby, __UNCONST(pkgname)); if (rv == 0) { if (!prop_dictionary_externalize_to_file(dict, plist)) rv = errno; diff --git a/lib/sha256.c b/lib/sha256.c index 9520955d076..7ebfb2e1393 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -371,8 +371,8 @@ SHA256_End(SHA256_CTX *ctx, uint8_t *buffer) SHA256_Final(digest, ctx); for (i = 0; i < SHA256_DIGEST_LENGTH; i++) { - *buffer++ = sha2_hex_digits[(*d & 0xf0) >> 4]; - *buffer++ = sha2_hex_digits[*d & 0x0f]; + *buffer++ = (uint8_t)sha2_hex_digits[(*d & 0xf0) >> 4]; + *buffer++ = (uint8_t)sha2_hex_digits[*d & 0x0f]; d++; } *buffer = (char) 0; diff --git a/vars.mk b/vars.mk index 607e5b6d996..20988ca3db9 100644 --- a/vars.mk +++ b/vars.mk @@ -12,4 +12,5 @@ CPPFLAGS += -I$(TOPDIR)/include -D_BSD_SOURCE -D_XOPEN_SOURCE=600 CPPFLAGS += -D_GNU_SOURCE WARNFLAGS ?= -pedantic -std=c99 -Wall -Wextra -Werror -Wshadow -Wformat=2 WARNFLAGS += -Wmissing-declarations -Wcomment -Wunused-macros -Wendif-labels +WARNFLAGS += -Wcast-qual -Wcast-align -Wsign-conversion CFLAGS += $(WARNFLAGS) -O2 -fPIC -DPIC