Silence GCC's "cast of pointer to integer of a different size" warning

When calculating hashes from pointers, it actually makes sense to cut off the most significant bits. In that case, said warning does not make a whole lot of sense. So let's just work around it by casting the pointer first to intptr_t and then casting up/down to the final integral type. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Oct 26, 2015 at 14:15 UTC 56a1a3ab449df33268776a8b72a301d3ee67ad8d
3 files changed +6 -4
compat/regex/regcomp.c
+4 -2
@@ -18,6 +18,8 @@
18 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA. */
20
21 +#include <stdint.h>
22 +
23 static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
24 size_t length, reg_syntax_t syntax);
25 static void re_compile_fastmap_iter (regex_t *bufp,
@@ -2577,7 +2579,7 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2579 old_tree = NULL;
2580
2581 if (elem->token.type == SUBEXP)
2580 - postorder (elem, mark_opt_subexp, (void *) (long) elem->token.opr.idx);
2582 + postorder (elem, mark_opt_subexp, (void *) (intptr_t) elem->token.opr.idx);
2583
2584 tree = create_tree (dfa, elem, NULL, (end == -1 ? OP_DUP_ASTERISK : OP_ALT));
2585 if (BE (tree == NULL, 0))
@@ -3806,7 +3808,7 @@ create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
3808 static reg_errcode_t
3809 mark_opt_subexp (void *extra, bin_tree_t *node)
3810 {
3809 - int idx = (int) (long) extra;
3811 + int idx = (int) (intptr_t) extra;
3812 if (node->token.type == SUBEXP && node->token.opr.idx == idx)
3813 node->token.opt_subexp = 1;
3814
pack-revindex.c
+1 -1
@@ -21,7 +21,7 @@ static int pack_revindex_hashsz;
21
22 static int pack_revindex_ix(struct packed_git *p)
23 {
24 - unsigned long ui = (unsigned long)p;
24 + unsigned long ui = (unsigned long)(intptr_t)p;
25 int i;
26
27 ui = ui ^ (ui >> 16); /* defeat structure alignment */
sha1_file.c
+1 -1
@@ -2014,7 +2014,7 @@ static unsigned long pack_entry_hash(struct packed_git *p, off_t base_offset)
2014 {
2015 unsigned long hash;
2016
2017 - hash = (unsigned long)p + (unsigned long)base_offset;
2017 + hash = (unsigned long)(intptr_t)p + (unsigned long)base_offset;
2018 hash += (hash >> 8) + (hash >> 16);
2019 return hash % MAX_DELTA_CACHE;
2020 }