Commit 646a94be5f01001e09796d03d5f6c077b21b9532

Edward Thomson 2018-11-18T23:15:56

Merge pull request #4847 from noahp/noahp/null-arg-fixes tests: 🌀 address two null argument instances

diff --git a/src/apply.c b/src/apply.c
index 614baf7..28d6cd8 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -348,8 +348,9 @@ static int apply_binary(
 			&patch->binary.old_file)) < 0)
 		goto done;
 
+	/* Verify that the resulting file with the reverse patch applied matches the source file */
 	if (source_len != reverse.size ||
-		memcmp(source, reverse.ptr, source_len) != 0) {
+		(source_len && memcmp(source, reverse.ptr, source_len) != 0)) {
 		error = apply_err("binary patch did not apply cleanly");
 		goto done;
 	}
diff --git a/tests/apply/fromfile.c b/tests/apply/fromfile.c
index 6d4379b..477e283 100644
--- a/tests/apply/fromfile.c
+++ b/tests/apply/fromfile.c
@@ -43,7 +43,8 @@ static int apply_patchfile(
 
 	if (error == 0) {
 		cl_assert_equal_i(new_len, result.size);
-		cl_assert(memcmp(new, result.ptr, new_len) == 0);
+		if (new_len)
+			cl_assert(memcmp(new, result.ptr, new_len) == 0);
 
 		cl_assert_equal_s(filename_expected, filename);
 		cl_assert_equal_i(mode_expected, mode);