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

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

Bug in 'patch' version 2.5.4


From: Gennady Yakovlev
Subject: Bug in 'patch' version 2.5.4
Date: Fri, 7 Sep 2001 21:35:57 +0400

When patching with -D <define> option, there is a bug in some cases.
 
For example, the old file is ex1.c (all files are attached) and the new file is ex2.c.
 
$ diff -wU 5 ex1.c ex2.c > ex.c.txt (attached)
 
Then
 
$ cp ex1.c ex.c
$ patch -lu -D USE2 -i ex.c.txt ex.c (attached)
 
You can see the first #ifdef, while it should be #ifndef.
 
I changed beginning of apply_hunk() function in patch.c as follows:
 
I changed marked below if_defined to not_defined.
 
while (old <= lastline) {
 if (pch_char(old) == '-') {
     assert (outstate->after_newline);
     if (! copy_till (outstate, where + old - 1))
  return FALSE;
     if (R_do_defines) {
  if (def_state == OUTSIDE) {
      fprintf (fp, outstate->after_newline + *****if_defined*****,
        R_do_defines);
      def_state = IN_IFNDEF;
  }
Additionally, i had to add starting newline (\n) symbol to initialization of "not_defined" variable.
Otherwise, patch outputs 'ifndef USE2' (without #).
 
static char const not_defined[] = "#ifndef %s\n"; to
static char const not_defined[] = "\n#ifndef %s\n";
Now it works.
 
I use cygwin on Windows and gcc 2.95.3-5. I took the 2.5.4 version from your web-archive.
 
 
 
With best regards,
    Gennady Yakovlev,
________________________
Paragon Software Group

Attachment: ex1.c
Description: Binary data

Attachment: ex2.c
Description: Binary data

Attachment: ex.c.txt
Description: Text document

Attachment: ex.c
Description: Binary data


reply via email to

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