threads / patch / 35939

patchdiffcore.h: be explicit about the signedness of is_binary

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

## tl;dr

3 messages between Feb 24, 2014 and Feb 24, 2014. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Richard Lowe· Feb 24, 2014, 00:54 UTC · lore

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(-)
Show changes to diffcore.h +1 −1
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· Feb 24, 2014, 02:09 UTC · re: Richard Lowe · lore

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

On Sun, Feb 23, 2014 at 07:54:47PM -0500, Richard Lowe wrote:
Show 6 quoted lines
> 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· Feb 24, 2014, 17:55 UTC · re: Richard Lowe · lore

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

Richard Lowe <richlowe@richlowe.net> writes:
Show 7 quoted lines
> 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.
Show 15 quoted lines
>  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;
>  };

← back to recent threads