bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: Bug#140247: [Fwd: bug in "patch" program]


From: Michael Fedrowitz
Subject: Re: Bug#140247: [Fwd: bug in "patch" program]
Date: Wed, 3 Apr 2002 17:01:21 +0200
User-agent: Mutt/1.3.28i

On Wed, Mar 27, 2002 at 11:19:42PM -0500, Jason Short wrote:

 Hi,

> There is a severe bug in the behavior of the -D option under patch.  If
> you have a patch patch.diff with some lines like:
> 
>    -   someline1
>    +   someline2
> 
> and you patch with "patch -p0 -D MY_DEFINE < patch.diff", the lines in
> the new file should become
> 
>    #ifndef MY_DEFINE
>      someline1;
>    #else
>      someline2;
>    #endif
> 
> but it does not.  Instead, it becomes
> 
>    #ifdef MY_DEFINE
>      someline1;
>    #else
>      someline2;
>    #endif
> 
> which is quite wrong, and makes the tool close to useless for this purpose.

While POSIX isn't entirely clear on which way round it should be, your
way seems to make a lot more sense to me. Besides patch behaves very
inconsistently as the following example demonstrates:

address@hidden:/tmp$ cat test 
foo
bar
baz
foo
bar
address@hidden:/tmp$ cat diff
--- test.orig   Wed Apr  3 16:55:38 2002
+++ test        Wed Apr  3 16:55:54 2002
@@ -1,5 +1,5 @@
 foo
-bar
 baz
 foo
+bar
 bar
address@hidden:/tmp$ patch -D TEST <diff
patching file test
address@hidden:/tmp$ cat test
foo
#ifdef TEST
bar
#endif /* TEST */
baz
foo
#ifdef TEST
bar
#endif /* TEST */
bar

Which is just plain broken.

> Fortunately, it appears to be easily fixable.  The attached patch
> (patch_ifndef.diff) should fix the problem.  But there may be other
> problems with this behavior (for non-unified-form patches), who knows?

No, this is the only instance of the problem. However your patch doesn't
quite work for me (the # of the #ifndef is missing). The patch below
works fine though and will be included in the next Debian upload.

-Michael


--- patch-2.5.4.orig/patch.c    Mon Aug 30 08:20:08 1999
+++ patch-2.5.4/patch.c Wed Apr  3 16:22:02 2002
@@ -1012,8 +1014,7 @@
                return FALSE;
            if (R_do_defines) {
                if (def_state == OUTSIDE) {
-                   fprintf (fp, outstate->after_newline + if_defined,
-                            R_do_defines);
+                   fprintf (fp, not_defined, R_do_defines);
                    def_state = IN_IFNDEF;
                }
                else if (def_state == IN_IFDEF) {



reply via email to

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