# [PATCH] diffcore.h: be explicit about the signedness of is_binary

3 messages from 2014-02-24 to 2014-02-24. Participants: Richard Lowe, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/35939

## Richard Lowe, 2014-02-24 00:54

Subject: [PATCH] diffcore.h: be explicit about the signedness of is_binary
Message-ID: <m2ob1xba94.fsf@richlowe.net>
URL: https://gitlist.dev/e/m2ob1xba94.fsf%40richlowe.net

```
Bitfields need to specify their signedness explicitly or the compiler is
free to default as it sees fit.  With compilers that default 'unsigned'
(SUNWspro 12 seems to do this) the tri-state nature of is_binary
vanishes and all files are treated as binary.

Signed-off-by: Richard Lowe <richlowe@richlowe.net>
---
 diffcore.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/diffcore.h b/diffcore.h
index 79de8cf..7c6f391 100644
--- a/diffcore.h
+++ b/diffcore.h
@@ -46,7 +46,7 @@ struct diff_filespec {
 	unsigned is_stdin : 1;
 	unsigned has_more_entries : 1; /* only appear in combined diff */
 	/* data should be considered "binary"; -1 means "don't know yet" */
-	int is_binary : 2;
+	signed int is_binary : 2;
 	struct userdiff_driver *driver;
 };
 
-- 
1.8.5.5

```

## Jeff King, 2014-02-24 02:09

Subject: Re: [PATCH] diffcore.h: be explicit about the signedness of is_binary
Message-ID: <20140224020940.GB7959@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20140224020940.GB7959%40sigill.intra.peff.net
In-Reply-To: <m2ob1xba94.fsf@richlowe.net>

```
On Sun, Feb 23, 2014 at 07:54:47PM -0500, Richard Lowe wrote:

> Bitfields need to specify their signedness explicitly or the compiler is
> free to default as it sees fit.  With compilers that default 'unsigned'
> (SUNWspro 12 seems to do this) the tri-state nature of is_binary
> vanishes and all files are treated as binary.
> 
> Signed-off-by: Richard Lowe <richlowe@richlowe.net>

Thanks, I wasn't aware of this corner of the standard when I wrote it.
Your fix is obviously correct.

-Peff

```

## Junio C Hamano, 2014-02-24 17:55

Subject: Re: [PATCH] diffcore.h: be explicit about the signedness of is_binary
Message-ID: <xmqqmwhg9yzf.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqmwhg9yzf.fsf%40gitster.dls.corp.google.com
In-Reply-To: <m2ob1xba94.fsf@richlowe.net>

```
Richard Lowe <richlowe@richlowe.net> writes:

> Bitfields need to specify their signedness explicitly or the compiler is
> free to default as it sees fit.  With compilers that default 'unsigned'
> (SUNWspro 12 seems to do this) the tri-state nature of is_binary
> vanishes and all files are treated as binary.
>
> Signed-off-by: Richard Lowe <richlowe@richlowe.net>
> ---

Looks good; thanks.

>  diffcore.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/diffcore.h b/diffcore.h
> index 79de8cf..7c6f391 100644
> --- a/diffcore.h
> +++ b/diffcore.h
> @@ -46,7 +46,7 @@ struct diff_filespec {
>  	unsigned is_stdin : 1;
>  	unsigned has_more_entries : 1; /* only appear in combined diff */
>  	/* data should be considered "binary"; -1 means "don't know yet" */
> -	int is_binary : 2;
> +	signed int is_binary : 2;
>  	struct userdiff_driver *driver;
>  };

```
