Commit 3c4e0ceef62a2452852f4a160360f1daa74bde7a

Patrick Steinhardt 2017-11-30T15:12:48

diff_generate: fix unsetting diff flags The macro `DIFF_FLAG_SET` can be used to set or unset a flag by modifying the diff's bitmask. While the case of setting the flag is handled correctly, the case of unsetting the flag was not. Instead of inverting the flags, we are inverting the value which is used to decide whether we want to set or unset the bits. The value being used here is a simple `bool` which is `false`. As that is being uplifted to `int` when getting the bitwise-complement, we will end up retaining all bits inside of the bitmask. As that's only ever used to set `GIT_DIFF_IGNORE_CASE`, we were actually always ignoring case for generated diffs. Fix that by instead getting the bitwise-complement of `FLAG`, not `VAL`.

1
2
3
4
5
6
7
8
9
10
11
12
13
diff --git a/src/diff_generate.c b/src/diff_generate.c
index f6cc04f..5d3e0c6 100644
--- a/src/diff_generate.c
+++ b/src/diff_generate.c
@@ -23,7 +23,7 @@
 	(((DIFF)->base.opts.flags & (FLAG)) == 0)
 #define DIFF_FLAG_SET(DIFF,FLAG,VAL) (DIFF)->base.opts.flags = \
 	(VAL) ? ((DIFF)->base.opts.flags | (FLAG)) : \
-	((DIFF)->base.opts.flags & ~(VAL))
+	((DIFF)->base.opts.flags & ~(FLAG))
 
 typedef struct {
 	struct git_diff base;