Skip to contentSkip to conversation

diffcore.h: be explicit about the signedness of is_binary

PATCH In review Richard Lowe 3 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 diffcore.h: be explicit about the signedness of is_binary

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.

---
 diffcore.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diffcore.h +1 -1
index 79de8cf..7c6f391 100644
@@ -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;
 };
 
Signature · 1 line
1.8.5.5
#1 lore raw
Quoted 6 lines · Richard Lowe

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.

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

-Peff

#2 lore raw
In reply to Richard Lowe
Quoted 7 lines · Richard Lowe

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.

---

Looks good; thanks.

Quoted 15 lines
 diffcore.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diffcore.h +1 -1
index 79de8cf..7c6f391 100644
@@ -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;
 };