Commit Diff


commit - 8ad022d28ef2432ad9fcd3b13fca28d0d813631f
commit + 15ac50e24fbf291e454c5cfbf3358c8ecfcf56a8
blob - f6dcef58bb67e1a01ce4a633f7928a184a56ebb1
blob + 0716796d2d5147368425b3edd6cc0e00d8ddc9ea
--- include/diff/diff_main.h
+++ include/diff/diff_main.h
@@ -115,12 +115,16 @@ void diff_data_free(struct diff_data *diff_data);
  * 0). Also works for diff_data that reference only a subsection of a file, always reflecting the global position in
  * the file (and not the relative position within the subsection). */
 #define diff_atom_root_idx(DIFF_DATA, ATOM) \
-	((ATOM) ? (ATOM) - ((DIFF_DATA)->root->atoms.head) : (DIFF_DATA)->root->atoms.len)
+	((ATOM) && ((ATOM) >= (DIFF_DATA)->root->atoms.head) \
+	 ? (unsigned int)((ATOM) - ((DIFF_DATA)->root->atoms.head)) \
+	 : (DIFF_DATA)->root->atoms.len)
 
 /* The atom's index within DIFF_DATA. For atoms divided by lines of text, this yields the line number (starting with
  * 0). */
 #define diff_atom_idx(DIFF_DATA, ATOM) \
-	((ATOM) ? (ATOM) - ((DIFF_DATA)->atoms.head) : (DIFF_DATA)->atoms.len)
+	((ATOM) && ((ATOM) >= (DIFF_DATA)->atoms.head) \
+	 ? (unsigned int)((ATOM) - ((DIFF_DATA)->atoms.head)) \
+	 : (DIFF_DATA)->atoms.len)
 
 #define foreach_diff_atom(ATOM, FIRST_ATOM, COUNT) \
 	for ((ATOM) = (FIRST_ATOM); \
blob - 17a6bffe139d685b095825de47ef10ff51e508b5
blob + 590243706ebb8b6777cc13e94fb338833ee013ba
--- lib/diff_patience.c
+++ lib/diff_patience.c
@@ -329,7 +329,7 @@ enum diff_rc diff_algo_patience(const struct diff_algo
 		if (i < lcs_count) {
 			atom = lcs[i];
 			atom_r = atom->patience.pos_in_other;
-			debug("lcs[%u] = left[%u] = right[%u]\n", i,
+			debug("lcs[%u] = left[%ld] = right[%ld]\n", i,
 			      diff_atom_idx(left, atom), diff_atom_idx(right, atom_r));
 			left_idx = atom->patience.identical_lines.start;
 			right_idx = atom_r->patience.identical_lines.start;