bug-patch
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-patch] patch-2.5.9 - patch.c:340: main: Assertion `hunk' failed


From: Andreas Gruenbacher
Subject: Re: [bug-patch] patch-2.5.9 - patch.c:340: main: Assertion `hunk' failed.
Date: Sat, 6 Jun 2009 18:59:18 +0200
User-agent: KMail/1.9.9

Alexander,

On Monday, 1 June 2009 13:42:08 Alexander Lamaison wrote:
> While transforming the patch code into a reusable library, I came
> across a bug that is also present in the mainstream patch code.
>
> When given an input appears to be a standard diff but has inconsistent
> indentation (attached as test_data), intuit_diff_type() returns
> NORMAL_DIFF as the type and sets the second line's indentation as the
> indent for the whole file.  there_is_another_patch()  continues to
> process the file but fails to find any hunks, presumably, because it
> gets confused by the indentation.  Eventually this causes the
> following assertion:
>
> $ ./patch --dry-run < test_input
> can't find file to patch at input line 1
> Perhaps you should have used the -p or --strip option?
> File to patch: patch
> patching file patch
> patch: patch.c:340: main: Assertion `hunk' failed.
> Aborted

very interesting. The assertion that triggers here has been removed as part of 
making patch act more reasonable for empty patches [1]. The disagreement 
between intuit_diff_type() and another_hunk() still hasn't been fixed though, 
and so in the latest version of the code, instead of aborting, we end up in 
an endless loop. This needs fixing.

  [1] http://git.savannah.gnu.org/cgit/patch.git/commit/?id=1994778

> I've attached a patch that forces intuit_diff_type() to return NO_DIFF
> when it finds that the indentation is inconsistent between the first
> two lines of a standard diff.

I don't see how you ended up checking for (p_indent > 0 && p_indent != 
indent). Shouldn't p_indent and indent always match to recognize a normal 
diff? How about something like this?

diff --git a/src/pch.c b/src/pch.c
index 0a136ae..2bf8066 100644
--- a/src/pch.c
+++ b/src/pch.c
@@ -570,10 +570,10 @@ intuit_diff_type (bool need_header)
        }
        if ((diff_type == NO_DIFF || diff_type == NORMAL_DIFF) &&
          last_line_was_command &&
+         p_indent == indent &&
          (strnEQ(s, "< ", 2) || strnEQ(s, "> ", 2)) ) {
            p_start = previous_line;
            p_sline = p_input_line - 1;
-           p_indent = indent;
            p_strip_trailing_cr = strip_trailing_cr;
            retval = NORMAL_DIFF;
            goto scan_exit;

> patch 2.5.9

GNU patch development has recently picked up speed again. The project is 
hosted at http://savannah.gnu.org/projects/patch; working against either the 
git tree or a recent snapshot would make things a little easier for me.

> Hope this helps.

Very much so, thanks!

Andreas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]