threads / patch / 3449

patchfix warning from pack-objects.c

Subject: [PATCH] fix warning from pack-objects.c

## tl;dr

2 messages between Feb 23, 2006 and Feb 23, 2006. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Luck, Tony· Feb 23, 2006, 22:42 UTC · lore
When compiling on ia64 I get this warning (from gcc 3.4.3):

gcc -o pack-objects.o -c -g -O2 -Wall -DSHA1_HEADER='<openssl/sha.h>' pack-objects.c pack-objects.c: In function `pack_revindex_ix': pack-objects.c:94: warning: cast from pointer to integer of different size

A double cast (first to long, then to int) shuts gcc up, but is there a better way?

Signed-off-by: Tony Luck <tony.luck@intel.com>
---
Show changes to pack-objects.c +1 −1
diff --git a/pack-objects.c b/pack-objects.c
index 8f352aa..c985fab 100644
--- a/pack-objects.c
+++ b/pack-objects.c
@@ -91,7 +91,7 @@ static int reused_delta = 0;
 
 static int pack_revindex_ix(struct packed_git *p)
 {
-	unsigned int ui = (unsigned int) p;
+	unsigned int ui = (unsigned int)(long)p;
 	int i;
 
 	ui = ui ^ (ui >> 16); /* defeat structure alignment */
Andreas Ericsson· Feb 23, 2006, 22:51 UTC · re: Luck, Tony · lore

Re: [PATCH] fix warning from pack-objects.c

Luck, Tony wrote:
Show 9 quoted lines
> When compiling on ia64 I get this warning (from gcc 3.4.3):
> 
> gcc -o pack-objects.o -c -g -O2 -Wall -DSHA1_HEADER='<openssl/sha.h>'  pack-objects.c
> pack-objects.c: In function `pack_revindex_ix':
> pack-objects.c:94: warning: cast from pointer to integer of different size
> 
> A double cast (first to long, then to int) shuts gcc up, but is there
> a better way?
> 

Make ui and i unsigned long and cast p to unsigned long (or perhaps ptrdiff_t is preferred?). On 32-bit archs it's no difference, but 64-bit archs can work with their native size. It's slightly faster (although I expect the compiler takes care of that anyways).

I noticed this earlier on my shiny AMD FX2 64-bit. The tests run just fine with my solution. I expect they will with yours as well.

Show 22 quoted lines
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> 
> ---
> 
> diff --git a/pack-objects.c b/pack-objects.c
> index 8f352aa..c985fab 100644
> --- a/pack-objects.c
> +++ b/pack-objects.c
> @@ -91,7 +91,7 @@ static int reused_delta = 0;
>  
>  static int pack_revindex_ix(struct packed_git *p)
>  {
> -	unsigned int ui = (unsigned int) p;
> +	unsigned int ui = (unsigned int)(long)p;
>  	int i;
>  
>  	ui = ui ^ (ui >> 16); /* defeat structure alignment */
> -
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

← back to recent threads