# [RFC/PATCH] fast-import: Fix compile warnings

8 messages from 2007-02-07 to 2007-02-08. Participants: Johannes Schindelin, Alex Riesen, Junio C Hamano, Shawn O. Pearce.
Thread: https://gitlist.dev/t/6717

## Johannes Schindelin, 2007-02-07 11:38

Subject: [RFC/PATCH] fast-import: Fix compile warnings
Message-ID: <Pine.LNX.4.63.0702071237360.22628@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0702071237360.22628%40wbgn013.biozentrum.uni-wuerzburg.de

```

Not on all platforms are size_t and unsigned long equivalent.
Since I do not know how portable %z is, I play safe, and just
cast the respective variables to unsigned long.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	I have no idea how portable %z is, but there are so many
	experts on this list. Care to enlighten me?

 fast-import.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index bc95a0d..2813ceb 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -882,7 +882,8 @@ static int store_object(
 	SHA_CTX c;
 	z_stream s;
 
-	hdrlen = sprintf((char*)hdr,"%s %lu",type_names[type],datlen) + 1;
+	hdrlen = sprintf((char*)hdr,"%s %lu", type_names[type],
+		(unsigned long)datlen) + 1;
 	SHA1_Init(&c);
 	SHA1_Update(&c, hdr, hdrlen);
 	SHA1_Update(&c, dat, datlen);
@@ -1427,7 +1428,8 @@ static void *cmd_data (size_t *size)
 		while (n < length) {
 			size_t s = fread(buffer + n, 1, length - n, stdin);
 			if (!s && feof(stdin))
-				die("EOF in data (%lu bytes remaining)", length - n);
+				die("EOF in data (%lu bytes remaining)",
+					(unsigned long)(length - n));
 			n += s;
 		}
 	}
@@ -2028,7 +2030,8 @@ int main(int argc, const char **argv)
 	fprintf(stderr, "      marks:     %10ju (%10ju unique    )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count);
 	fprintf(stderr, "      atoms:     %10u\n", atom_cnt);
 	fprintf(stderr, "Memory total:    %10ju KiB\n", (total_allocd + alloc_count*sizeof(struct object_entry))/1024);
-	fprintf(stderr, "       pools:    %10lu KiB\n", total_allocd/1024);
+	fprintf(stderr, "       pools:    %10lu KiB\n",
+		(unsigned long)(total_allocd / 1024));
 	fprintf(stderr, "     objects:    %10ju KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
 	fprintf(stderr, "---------------------------------------------------------------------\n");
 	pack_report();
-- 
1.5.0.rc3.2124.g3861-dirty

```

## Alex Riesen, 2007-02-07 12:19

Subject: Re: [RFC/PATCH] fast-import: Fix compile warnings
Message-ID: <81b0412b0702070419t2293f776wb4f3f7beb76c986c@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0702070419t2293f776wb4f3f7beb76c986c%40mail.gmail.com
In-Reply-To: <Pine.LNX.4.63.0702071237360.22628@wbgn013.biozentrum.uni-wuerzburg.de>

```
On 2/7/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>
>         I have no idea how portable %z is, but there are so many
>         experts on this list. Care to enlighten me?
>

IEEE Std 1003.1[1] mentions it, but I never was able to rely on it:
AIX, Solaris, QNX-libc at least didn't have it, last time I checked.
Micro$oft doesn't have it, of course.

[1] http://www.opengroup.org/onlinepubs/009695399/functions/fprintf.html

```

## Junio C Hamano, 2007-02-07 17:24

Subject: Re: [RFC/PATCH] fast-import: Fix compile warnings
Message-ID: <7vzm7p7uf9.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vzm7p7uf9.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.63.0702071237360.22628@wbgn013.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Not on all platforms are size_t and unsigned long equivalent.
> Since I do not know how portable %z is, I play safe, and just
> cast the respective variables to unsigned long.

The format "%s %lu" is consistent with what write_sha1_file_prepare()
and unpack_sha1_header() uses, so that should be safe enough.

However, your patch does not apply.

```

## Johannes Schindelin, 2007-02-07 17:35

Subject: Re: [RFC/PATCH] fast-import: Fix compile warnings
Message-ID: <Pine.LNX.4.63.0702071829450.22628@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0702071829450.22628%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <7vzm7p7uf9.fsf@assigned-by-dhcp.cox.net>

```
Hi,

On Wed, 7 Feb 2007, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > Not on all platforms are size_t and unsigned long equivalent.
> > Since I do not know how portable %z is, I play safe, and just
> > cast the respective variables to unsigned long.
> 
> The format "%s %lu" is consistent with what write_sha1_file_prepare()
> and unpack_sha1_header() uses, so that should be safe enough.

So, should we cast to (unsigned long) to make the gcc warning go away, or 
do we not care at all?

> However, your patch does not apply.

Hmm. Strange, I thought that I only changed the in_merge_bases() line... 
Will have a look tomorrow.

Ciao,
Dscho

```

## Junio C Hamano, 2007-02-07 17:47

Subject: Re: [RFC/PATCH] fast-import: Fix compile warnings
Message-ID: <7vveid7tce.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vveid7tce.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.63.0702071829450.22628@wbgn013.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

>> However, your patch does not apply.
>
> Hmm. Strange, I thought that I only changed the in_merge_bases() line... 
> Will have a look tomorrow.

Sorry, but not to worry.  It was because Shawn had a few updates
ahead of you.

```

## Shawn O. Pearce, 2007-02-08 07:03

Subject: Re: [RFC/PATCH] fast-import: Fix compile warnings
Message-ID: <20070208070342.GA3746@spearce.org>
URL: https://gitlist.dev/e/20070208070342.GA3746%40spearce.org
In-Reply-To: <Pine.LNX.4.63.0702071237360.22628@wbgn013.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> Not on all platforms are size_t and unsigned long equivalent.
> Since I do not know how portable %z is, I play safe, and just
> cast the respective variables to unsigned long.

We do this elsewhere in Git.  blobs are using unsigned long in
sha1_file.c for their length; I chose to size_t in gfi as that's
what the type is for...  but then look at the mess.

I applied this patch to my tree and pushed it to repo.or.cz.
This last hunk:
 
> @@ -2028,7 +2030,8 @@ int main(int argc, const char **argv)
>  	fprintf(stderr, "      marks:     %10ju (%10ju unique    )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count);
>  	fprintf(stderr, "      atoms:     %10u\n", atom_cnt);
>  	fprintf(stderr, "Memory total:    %10ju KiB\n", (total_allocd + alloc_count*sizeof(struct object_entry))/1024);
> -	fprintf(stderr, "       pools:    %10lu KiB\n", total_allocd/1024);
> +	fprintf(stderr, "       pools:    %10lu KiB\n",
> +		(unsigned long)(total_allocd / 1024));
>  	fprintf(stderr, "     objects:    %10ju KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
>  	fprintf(stderr, "---------------------------------------------------------------------\n");
>  	pack_report();

was the only part that did not apply cleanly, but that was easily
fixed by tossing an extra tab at the start of each line, as this
hunk was shifted in one level by a recent commit that Junio has
not pushed out to master.

-- 
Shawn.

```

## Junio C Hamano, 2007-02-08 07:10

Subject: Re: [RFC/PATCH] fast-import: Fix compile warnings
Message-ID: <7vejp12kh5.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vejp12kh5.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20070208070342.GA3746@spearce.org>

```
"Shawn O. Pearce" <spearce@spearce.org> writes:

> was the only part that did not apply cleanly, but that was easily
> fixed by tossing an extra tab at the start of each line, as this
> hunk was shifted in one level by a recent commit that Junio has
> not pushed out to master.

Actually it has been pushed out quite a while ago, but as usual
kernel.org is taking its sweet time to mirror it out.

```

## Shawn O. Pearce, 2007-02-08 07:16

Subject: Re: [RFC/PATCH] fast-import: Fix compile warnings
Message-ID: <20070208071603.GB3746@spearce.org>
URL: https://gitlist.dev/e/20070208071603.GB3746%40spearce.org
In-Reply-To: <7vejp12kh5.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano <junkio@cox.net> wrote:
> "Shawn O. Pearce" <spearce@spearce.org> writes:
> 
> > was the only part that did not apply cleanly, but that was easily
> > fixed by tossing an extra tab at the start of each line, as this
> > hunk was shifted in one level by a recent commit that Junio has
> > not pushed out to master.
> 
> Actually it has been pushed out quite a while ago, but as usual
> kernel.org is taking its sweet time to mirror it out.

Nice.  OK.  So don't pull in my repo.or.cz branch right now. :-)

-- 
Shawn.

```
