]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix diff generation with line added at start
authorSebastian Hahn <sebastian@torproject.org>
Mon, 17 Apr 2017 08:07:31 +0000 (10:07 +0200)
committerSebastian Hahn <sebastian@torproject.org>
Mon, 17 Apr 2017 08:10:46 +0000 (10:10 +0200)
The consdiff generation logic would skip over lines added at the start of the
second file, and generate a diff that it would the immediately refuse because
it couldn't be used to reproduce the second file from the first. Fixes #21996.

src/or/consdiff.c
src/test/test_consdiff.c

index d2a2af1b5facd01dad7651e6bdbcf7b875a92c41..cd22fd44a138b9ef3817d705b6e53b15ef37a43e 100644 (file)
@@ -671,7 +671,7 @@ gen_ed_diff(const smartlist_t *cons1, const smartlist_t *cons2,
    */
   i1=len1-1, i2=len2-1;
   char buf[128];
-  while (i1 > 0 || i2 > 0) {
+  while (i1 >= 0 || i2 >= 0) {
 
     int start1x, start2x, end1, end2, added, deleted;
 
index 1b4e2ad3c1e6ca4ae4f8f89c8abb2728de651b60..193d524c8107bb2bf1753fda173364cb91bd9186 100644 (file)
@@ -622,6 +622,17 @@ test_consdiff_gen_ed_diff(void *arg)
   tt_str_eq_line(".", smartlist_get(diff, 5));
   tt_str_eq_line("2d", smartlist_get(diff, 6));
 
+  smartlist_clear(cons1);
+  smartlist_clear(cons2);
+  consensus_split_lines(cons1, "B\n", area);
+  consensus_split_lines(cons2, "A\nB\n", area);
+  diff = gen_ed_diff(cons1, cons2, area);
+  tt_ptr_op(NULL, OP_NE, diff);
+  tt_int_op(3, OP_EQ, smartlist_len(diff));
+  tt_str_eq_line("0a", smartlist_get(diff, 0));
+  tt_str_eq_line("A", smartlist_get(diff, 1));
+  tt_str_eq_line(".", smartlist_get(diff, 2));
+
   /* TODO: small real use-cases, i.e. consensuses. */
 
  done: