# [PATCH 8/10] Fix some minor warnings to allow -Werror.

4 messages from 2006-08-02 to 2006-08-02. Participants: Ramsay Jones, Junio C Hamano, Rocco Rutte.
Thread: https://gitlist.dev/t/5083

## Ramsay Jones, 2006-08-02 01:03

Subject: [PATCH 8/10] Fix some minor warnings to allow -Werror.
Message-ID: <00be01c6b5cf$7f7e9e20$c47eedc1@ramsay1.demon.co.uk>
URL: https://gitlist.dev/e/00be01c6b5cf%247f7e9e20%24c47eedc1%40ramsay1.demon.co.uk

```
Signed-off-by: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk>
---
 builtin-mailinfo.c |    3 ++-
 diff.c             |    1 +
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 3e40747..bb5e7b7 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -531,7 +531,8 @@ static int decode_b_segment(char *in, ch
 static void convert_to_utf8(char *line, char *charset)
 {
 #ifndef NO_ICONV
-	char *in, *out;
+	const char *in;
+	char *out;
 	size_t insize, outsize, nrc;
 	char outbuf[4096]; /* cheat */
 	static char latin_one[] = "latin1";
diff --git a/diff.c b/diff.c
index 5a71489..81630c0 100644
--- a/diff.c
+++ b/diff.c
@@ -614,6 +614,7 @@ static void emit_binary_diff(mmfile_t *o
 	 * whichever is smaller.
 	 */
 	delta = NULL;
+	orig_size = 0;
 	deflated = deflate_it(two->ptr, two->size, &deflate_size);
 	if (one->size && two->size) {
 		delta = diff_delta(one->ptr, one->size,
-- 
1.4.1


From 262b57917ff01f74c95670ae59f1cd59a9024135 Mon Sep 17 00:00:00 2001
From: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk>
Date: Sun, 30 Jul 2006 17:06:25 +0100
Subject: [PATCH 8/10] Fix some minor warnings to allow -Werror.

Signed-off-by: Ramsay Allan Jones <ramsay@ramsay1.demon.co.uk>
---
 builtin-mailinfo.c |    3 ++-
 diff.c             |    1 +
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 3e40747..bb5e7b7 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -531,7 +531,8 @@ static int decode_b_segment(char *in, ch
 static void convert_to_utf8(char *line, char *charset)
 {
 #ifndef NO_ICONV
-	char *in, *out;
+	const char *in;
+	char *out;
 	size_t insize, outsize, nrc;
 	char outbuf[4096]; /* cheat */
 	static char latin_one[] = "latin1";
diff --git a/diff.c b/diff.c
index 5a71489..81630c0 100644
--- a/diff.c
+++ b/diff.c
@@ -614,6 +614,7 @@ static void emit_binary_diff(mmfile_t *o
 	 * whichever is smaller.
 	 */
 	delta = NULL;
+	orig_size = 0;
 	deflated = deflate_it(two->ptr, two->size, &deflate_size);
 	if (one->size && two->size) {
 		delta = diff_delta(one->ptr, one->size,
-- 
1.4.1


```

## Junio C Hamano, 2006-08-02 07:46

Subject: Re: [PATCH 8/10] Fix some minor warnings to allow -Werror.
Message-ID: <7vvepbvauo.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vvepbvauo.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <00be01c6b5cf$7f7e9e20$c47eedc1@ramsay1.demon.co.uk>

```
"Ramsay Jones" <ramsay@ramsay1.demon.co.uk> writes:

> diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
> index 3e40747..bb5e7b7 100644
> --- a/builtin-mailinfo.c
> +++ b/builtin-mailinfo.c
> @@ -531,7 +531,8 @@ static int decode_b_segment(char *in, ch
>  static void convert_to_utf8(char *line, char *charset)
>  {
>  #ifndef NO_ICONV
> -	char *in, *out;
> +	const char *in;
> +	char *out;
>  	size_t insize, outsize, nrc;
>  	char outbuf[4096]; /* cheat */
>  	static char latin_one[] = "latin1";

This kills the compilation with:

gcc -o builtin-mailinfo.o -c -O2 -Werror -ansi -pedantic -std=c99 -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wall -Wdeclaration-after-statement -g -DSHA1_HEADER='<openssl/sha.h>' -DNO_STRLCPY builtin-mailinfo.c
cc1: warnings being treated as errors
builtin-mailinfo.c: In function 'convert_to_utf8':
builtin-mailinfo.c:561: warning: passing argument 2 of 'iconv' from incompatible pointer type

where the line 561 reads:

	nrc = iconv(conv, &in, &insize, &out, &outsize);

> diff --git a/diff.c b/diff.c
> index 5a71489..81630c0 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -614,6 +614,7 @@ static void emit_binary_diff(mmfile_t *o
>  	 * whichever is smaller.
>  	 */
>  	delta = NULL;
> +	orig_size = 0;
>  	deflated = deflate_it(two->ptr, two->size, &deflate_size);
>  	if (one->size && two->size) {
>  		delta = diff_delta(one->ptr, one->size,

This is not wrong per se, but is working around a stupid compiler that
do not understand the dataflow.  orig_size is only used when
delta is non NULL, and when delta is non NULL, the variable is
always set.  Not very happy but is acceptable.

```

## Rocco Rutte, 2006-08-02 08:53

Subject: Re: [PATCH 8/10] Fix some minor warnings to allow -Werror.
Message-ID: <20060802085330.GA6595@peter.daprodeges.fqdn.th-h.de>
URL: https://gitlist.dev/e/20060802085330.GA6595%40peter.daprodeges.fqdn.th-h.de
In-Reply-To: <7vvepbvauo.fsf@assigned-by-dhcp.cox.net>

```
Hi,

* Junio C Hamano [06-08-02 00:46:23 -0700] wrote:

[...]

>This kills the compilation with:
>
>gcc -o builtin-mailinfo.o -c -O2 -Werror -ansi -pedantic -std=c99 -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wall -Wdeclaration-after-statement -g -DSHA1_HEADER='<openssl/sha.h>' -DNO_STRLCPY builtin-mailinfo.c
>cc1: warnings being treated as errors
>builtin-mailinfo.c: In function 'convert_to_utf8':
>builtin-mailinfo.c:561: warning: passing argument 2 of 'iconv' from incompatible pointer type
>
>where the line 561 reads:
>
>	nrc = iconv(conv, &in, &insize, &out, &outsize);

It depends on the iconv() implementation as what the input pointer is 
defined: some use just 'char*' while others use 'const char*' (GNU 
libiconv IIRC).

   bye, Rocco
-- 
:wq!

```

## Ramsay Jones, 2006-08-02 18:47

Subject: RE: [PATCH 8/10] Fix some minor warnings to allow -Werror.
Message-ID: <001c01c6b664$27536740$c47eedc1@ramsay1.demon.co.uk>
URL: https://gitlist.dev/e/001c01c6b664%2427536740%24c47eedc1%40ramsay1.demon.co.uk
In-Reply-To: <7vvepbvauo.fsf@assigned-by-dhcp.cox.net>

```

On Wed, 2006-08-02 at 8:46, Junio C Hamano wrote:
> 
> "Ramsay Jones" <ramsay@ramsay1.demon.co.uk> writes:
> 
> > diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
> > index 3e40747..bb5e7b7 100644
> > --- a/builtin-mailinfo.c
> > +++ b/builtin-mailinfo.c
> > @@ -531,7 +531,8 @@ static int decode_b_segment(char *in, ch
> >  static void convert_to_utf8(char *line, char *charset)
> >  {
> >  #ifndef NO_ICONV
> > -	char *in, *out;
> > +	const char *in;
> > +	char *out;
> >  	size_t insize, outsize, nrc;
> >  	char outbuf[4096]; /* cheat */
> >  	static char latin_one[] = "latin1";
> 
> This kills the compilation with:
> 
> gcc -o builtin-mailinfo.o -c -O2 -Werror -ansi -pedantic -std=c99 
> -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -Wall 
> -Wdeclaration-after-statement -g -DSHA1_HEADER='<openssl/sha.h>' 
> -DNO_STRLCPY builtin-mailinfo.c
> cc1: warnings being treated as errors
> builtin-mailinfo.c: In function 'convert_to_utf8':
> builtin-mailinfo.c:561: warning: passing argument 2 of 'iconv' 
> from incompatible pointer type
> 
> where the line 561 reads:
> 
> 	nrc = iconv(conv, &in, &insize, &out, &outsize);
> 

OK, so I get exactly the same if I don't make the indicated change!
The second param of iconv() must have changed from const char* to char*
at some point in the last six years.
Just ignore this.

> > diff --git a/diff.c b/diff.c
> > index 5a71489..81630c0 100644
> > --- a/diff.c
> > +++ b/diff.c
> > @@ -614,6 +614,7 @@ static void emit_binary_diff(mmfile_t *o
> >  	 * whichever is smaller.
> >  	 */
> >  	delta = NULL;
> > +	orig_size = 0;
> >  	deflated = deflate_it(two->ptr, two->size, &deflate_size);
> >  	if (one->size && two->size) {
> >  		delta = diff_delta(one->ptr, one->size,
> 
> This is not wrong per se, but is working around a stupid compiler that
> do not understand the dataflow.  orig_size is only used when
> delta is non NULL, and when delta is non NULL, the variable is
> always set.  Not very happy but is acceptable.
> 

Yes, you are absolutely correct. I agree it would be nice if gcc was
"fixed" so that it could detect this situation, but I'm not going to
hold my breath. It just seemed to be the lesser evil.

Ramsay

```
