From e43fc9342864a8fa0f19a64b95a2b6ef33fa0c78 Mon Sep 17 00:00:00 2001 From: "Xibo.Wang" Date: Thu, 29 Dec 2022 18:05:24 +0800 Subject: [PATCH 1/2] Make the (debug & 2) output more useful * src/pch.c (another_hunk): In the (debug & 2) output, fix how empty lines that are not part of the patch context are printed. Also, add newlines to lines that are missing them to keep the output readable. --- ...-Make-the-debug-2-output-more-useful.patch | 47 +++++++++++++++++++ patch.spec | 6 ++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 backport-Make-the-debug-2-output-more-useful.patch diff --git a/backport-Make-the-debug-2-output-more-useful.patch b/backport-Make-the-debug-2-output-more-useful.patch new file mode 100644 index 0000000..3f036ee --- /dev/null +++ b/backport-Make-the-debug-2-output-more-useful.patch @@ -0,0 +1,47 @@ +From 4be3ee4d25fc777a2508fdd03dc8f701cf4ca91d Mon Sep 17 00:00:00 2001 +From: Andreas Gruenbacher +Date: Fri, 17 Aug 2018 10:31:22 +0200 +Subject: [PATCH] Make the (debug & 2) output more useful + +* src/pch.c (another_hunk): In the (debug & 2) output, fix how empty +lines that are not part of the patch context are printed. Also, add +newlines to lines that are missing them to keep the output readable. + +Signed-off-by: Xibo.Wang +--- + src/pch.c | 12 +++++++++--- + 1 file changed, 9 insertions(+), 3 deletions(-) + +diff --git a/src/pch.c b/src/pch.c +index 4368561..aa0caf4 100644 +--- a/src/pch.c ++++ b/src/pch.c +@@ -1923,8 +1923,13 @@ another_hunk (enum diff difftype, bool rev) + lin i; + + for (i = 0; i <= p_end + 1; i++) { +- fprintf (stderr, "%s %c", +- format_linenum (numbuf0, i), ++ fputs (format_linenum (numbuf0, i), stderr); ++ if (p_Char[i] == '\n') ++ { ++ fputc('\n', stderr); ++ continue; ++ } ++ fprintf (stderr, " %c", + p_Char[i]); + if (p_Char[i] == '*') + fprintf (stderr, " %s,%s\n", +@@ -1937,7 +1942,8 @@ another_hunk (enum diff difftype, bool rev) + else if (p_Char[i] != '^') + { + fputs(" |", stderr); +- pch_write_line (i, stderr); ++ if (! pch_write_line (i, stderr)) ++ fputc('\n', stderr); + } + else + fputc('\n', stderr); +-- +1.8.3.1 + diff --git a/patch.spec b/patch.spec index 916502d..8a69cee 100644 --- a/patch.spec +++ b/patch.spec @@ -1,6 +1,6 @@ Name: patch Version: 2.7.6 -Release: 17 +Release: 18 Summary: Utiliity which applies a patch file to original files. License: GPLv3+ URL: http://www.gnu.org/software/patch/patch.html @@ -18,6 +18,7 @@ Patch9: Avoid-set_file_attributes-sign-conversion-warnings.patch Patch10: Test-suite-compatibility-fixes.patch Patch11: Test-suite-fix-Korn-shell-incompatibility.patch Patch12: backport-maint-avoid-warnings-from-GCC8.patch +Patch13: backport-Make-the-debug-2-output-more-useful.patch BuildRequires: gcc libselinux-devel libattr-devel ed Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-root @@ -60,6 +61,9 @@ CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE" %{_mandir}/man1/* %changelog +* Wed Dec 28 2022 Xibo.Wang - 2.7.6-18 +- Make the (debug & 2) output more useful + * Wed Dec 28 2022 Xibo.Wang - 2.7.6-17 - maint: avoid warnings from GCC8 From f6cd85537ab128cf1c6dfa3c3eca9aeff8f294c4 Mon Sep 17 00:00:00 2001 From: "Xibo.Wang" Date: Thu, 29 Dec 2022 18:15:19 +0800 Subject: [PATCH 2/2] Improve support for memory leak detection When building with the address sanitizer on, free some more resources before exiting. (This is unnecessary when not looking for memory leaks.) * src/patch.c (init_files_to_delete): Add dispose function for freeing filenames. --- ...ve-support-for-memory-leak-detection.patch | 55 +++++++++++++++++++ patch.spec | 6 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 backport--Improve-support-for-memory-leak-detection.patch diff --git a/backport--Improve-support-for-memory-leak-detection.patch b/backport--Improve-support-for-memory-leak-detection.patch new file mode 100644 index 0000000..fd2992c --- /dev/null +++ b/backport--Improve-support-for-memory-leak-detection.patch @@ -0,0 +1,55 @@ +From 312b793db6f549a3d4036b5d0ed2265c451ede15 Mon Sep 17 00:00:00 2001 +From: Andreas Gruenbacher +Date: Thu, 27 Jun 2019 11:02:02 +0200 +Subject: [PATCH] Improve support for memory leak detection + +When building with the address sanitizer on, free some more resources before +exiting. (This is unnecessary when not looking for memory leaks.) +* src/patch.c (init_files_to_delete): Add dispose function for freeing +filenames. + +Signed-off-by: Xibo.Wang +--- + src/patch.c | 16 +++++++++++++++- + 1 file changed, 15 insertions(+), 1 deletion(-) + +diff --git a/src/patch.c b/src/patch.c +index 99a5904..e57cf19 100644 +--- a/src/patch.c ++++ b/src/patch.c +@@ -36,6 +36,10 @@ + #include + #include + ++#ifdef __SANITIZE_ADDRESS__ ++# define FREE_BEFORE_EXIT ++#endif ++ + /* procedures */ + + static FILE *create_output_file (char const *, int); +@@ -1777,10 +1781,20 @@ struct file_to_delete { + + static gl_list_t files_to_delete; + ++#ifdef FREE_BEFORE_EXIT ++void dispose_file_to_delete (const void *elt) ++{ ++ free ((void *) elt); ++} ++#else ++#define dispose_file_to_delete NULL ++#endif ++ + static void + init_files_to_delete (void) + { +- files_to_delete = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true); ++ files_to_delete = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, ++ dispose_file_to_delete, true); + } + + static void +-- +1.8.3.1 + diff --git a/patch.spec b/patch.spec index 8a69cee..b988c43 100644 --- a/patch.spec +++ b/patch.spec @@ -1,6 +1,6 @@ Name: patch Version: 2.7.6 -Release: 18 +Release: 19 Summary: Utiliity which applies a patch file to original files. License: GPLv3+ URL: http://www.gnu.org/software/patch/patch.html @@ -19,6 +19,7 @@ Patch10: Test-suite-compatibility-fixes.patch Patch11: Test-suite-fix-Korn-shell-incompatibility.patch Patch12: backport-maint-avoid-warnings-from-GCC8.patch Patch13: backport-Make-the-debug-2-output-more-useful.patch +Patch14: backport--Improve-support-for-memory-leak-detection.patch BuildRequires: gcc libselinux-devel libattr-devel ed Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-root @@ -61,6 +62,9 @@ CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE" %{_mandir}/man1/* %changelog +* Wed Dec 28 2022 Xibo.Wang - 2.7.6-19 +- Improve support for memory leak detection + * Wed Dec 28 2022 Xibo.Wang - 2.7.6-18 - Make the (debug & 2) output more useful