Download raw body.
diff: Function names appearing inside diff context
Hi, There is an issue that if a function name appears within the context it isn't discovered correctly and we instead get the previously declared function in the file. I am not sure how to fix this. I can't quite grasp why the range for the left side contains the context already. I have included a patch that resolves a single case, but I think I am missing how to discover the correct offset. The patch also includes tests that exercise this case. gdiff exhibits this error, but openbsd diff doesn't seem to. I'd love some advice on how to construct the start of the search correctly. - Tom diff --git a/lib/diff_output.c b/lib/diff_output.c index 3047221..4fa8900 100644 --- a/lib/diff_output.c +++ b/lib/diff_output.c @@ -280,7 +280,7 @@ diff_output_match_function_prototype(char *prototype, size_t prototype_size, if (result->left->atoms.len > 0 && cc->left.start > 0) { data = result->left; - start_atom = &data->atoms.head[cc->left.start - 1]; + start_atom = &data->atoms.head[cc->left.start + 3]; } else return DIFF_RC_OK; diff --git a/test/expect124.diff b/test/expect124.diff new file mode 100644 index 0000000..2ae051a --- /dev/null +++ b/test/expect124.diff @@ -0,0 +1,9 @@ +--- test124.left-p.txt ++++ test124.right-p.txt +@@ -11,5 +11,5 @@ return_test(int test) { + + struct testfile * + return_test(int test) { +- return NULL; ++ return test*2; + } diff --git a/test/test124.left-p.txt b/test/test124.left-p.txt new file mode 100644 index 0000000..2c57789 --- /dev/null +++ b/test/test124.left-p.txt @@ -0,0 +1,15 @@ +static void +doSomethingThenPrintHello(int test) +{ + test = test << 4; + if (test % 8 == 6) { + return; + } + + print("goodbye\n"); +} + +struct testfile * +return_test(int test) { + return NULL; +} diff --git a/test/test124.right-p.txt b/test/test124.right-p.txt new file mode 100644 index 0000000..9f2252e --- /dev/null +++ b/test/test124.right-p.txt @@ -0,0 +1,15 @@ +static void +doSomethingThenPrintHello(int test) +{ + test = test << 4; + if (test % 8 == 6) { + return; + } + + print("goodbye\n"); +} + +struct testfile * +return_test(int test) { + return test*2; +}
diff: Function names appearing inside diff context