Commit Diff


commit - 724967e914b1604b54fab356ad4ce6c0feae2358
commit + 13497fffa978aafa3c52c4b4922ba184de87bcf0
blob - 5e5cb01b5967039da07fc784a8ad645732e6efda
blob + 792940d176efeada092e96fee5f42111ef1fb6a7
--- lib/diff_main.c
+++ lib/diff_main.c
@@ -382,6 +382,8 @@ diff_algo_none(const struct diff_algo_config *algo_con
 	unsigned int r_len = state->right.atoms.len;
 	unsigned int equal_atoms_start = 0;
 	unsigned int equal_atoms_end = 0;
+	unsigned int l_idx = 0;
+	unsigned int r_idx = 0;
 
 	while (equal_atoms_start < l_len
 	       && equal_atoms_start < r_len) {
@@ -416,33 +418,35 @@ diff_algo_none(const struct diff_algo_config *algo_con
 					  &r[0],
 					  equal_atoms_start))
 			return ENOMEM;
+		l_idx += equal_atoms_start;
+		r_idx += equal_atoms_start;
 	}
 
 	/* Add a "minus" chunk with all lines from the left. */
 	if (equal_atoms_start + equal_atoms_end < l_len) {
+		unsigned int add_len = l_len - equal_atoms_start - equal_atoms_end;
 		if (!diff_state_add_chunk(state, true,
-					  &l[equal_atoms_start],
-					  l_len - equal_atoms_start - equal_atoms_end,
-					  NULL, 0))
-		    return ENOMEM;
+					  &l[l_idx], add_len,
+					  &r[r_idx], 0))
+			return ENOMEM;
+		l_idx += add_len;
 	}
 
 	/* Add a "plus" chunk with all lines from the right. */
 	if (equal_atoms_start + equal_atoms_end < r_len) {
+		unsigned int add_len = r_len - equal_atoms_start - equal_atoms_end;
 		if (!diff_state_add_chunk(state, true,
-					  NULL, 0,
-					  &r[equal_atoms_start],
-					  r_len - equal_atoms_start - equal_atoms_end))
-		return ENOMEM;
+					  &l[equal_atoms_start], 0,
+					  &r[equal_atoms_start], add_len))
+			return ENOMEM;
+		r_idx += add_len;
 	}
 
 	/* Add a chunk of equal lines at the end */
 	if (equal_atoms_end) {
 		if (!diff_state_add_chunk(state, true,
-					  &l[l_len - equal_atoms_end],
-					  equal_atoms_end,
-					  &r[r_len - equal_atoms_end],
-					  equal_atoms_end))
+					  &l[l_idx], equal_atoms_end,
+					  &r[r_idx], equal_atoms_end))
 			return ENOMEM;
 	}