[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fwd: Serious bug in patch with --ifdef option
From: |
Pete Buechler |
Subject: |
Fwd: Serious bug in patch with --ifdef option |
Date: |
Sun, 5 Nov 2000 20:14:48 -0700 |
WHOOPS! Had trouble spelling your address, trying again ...
---------- Forwarded Message ----------
Subject: Serious bug in patch with --ifdef option
Date: Sat, 4 Nov 2000 09:20:51 -0700
From: Pete Buechler <address@hidden>
To: address@hidden
Dear maintainers -
I found a serious bug in patch when used with unified diffs and the
--ifdef option. It was using the directive #ifdef on lines that it
should have printed #ifndef. Enclosed please find a patch to repair
this.
While I had patch open, I decided that it was inconsistent for it to
comment the #endif so that it would be easy to match it to its
corresponding #ifdef, but not to comment the #else. So I created a
patch to make it comment both. I have kept the patches separate so that
you can accept one without the other more easily.
In addition, I am attaching two files to be used for testing. To see
the current, incorrect behavior, perform the following two commands:
diff -u test1.txt test2.txt > test.diff
patch -b -p0 --ifdef=NEW < test.diff
If you look at the resulting test1.txt, you will see the errors. This
can also be used to test the results of the two patches when applied to
patch.
THE BUGFIX PATCH:
--- patch.c~ Sun Aug 29 23:20:08 1999
+++ patch.c Sat Nov 4 09:07:27 2000
@@ -1012,7 +1012,7 @@
return FALSE;
if (R_do_defines) {
if (def_state == OUTSIDE) {
- fprintf (fp, outstate->after_newline + if_defined,
+ fprintf (fp, outstate->after_newline + not_defined,
R_do_defines);
def_state = IN_IFNDEF;
}
AND NOW THE ENHANCEMENT PATCH:
--- patch.c~ Sat Nov 4 09:07:27 2000
+++ patch.c Sat Nov 4 09:08:23 2000
@@ -89,7 +89,7 @@
static char const *do_defines; /* symbol to patch using ifdef, ifndef,
etc. */
static char const if_defined[] = "\n#ifdef %s\n";
static char const not_defined[] = "#ifndef %s\n";
-static char const else_defined[] = "\n#else\n";
+static char const else_defined[] = "\n#else /* %s */\n";
static char const end_defined[] = "\n#endif /* %s */\n";
static int Argc;
@@ -1017,7 +1017,8 @@
def_state = IN_IFNDEF;
}
else if (def_state == IN_IFDEF) {
- fprintf (fp, outstate->after_newline + else_defined);
+ fprintf (fp, outstate->after_newline + else_defined,
+ R_do_defines);
def_state = IN_ELSE;
}
if (ferror (fp))
@@ -1036,7 +1037,8 @@
return FALSE;
if (R_do_defines) {
if (def_state == IN_IFNDEF) {
- fprintf (fp, outstate->after_newline + else_defined);
+ fprintf (fp, outstate->after_newline + else_defined,
+ R_do_defines);
def_state = IN_ELSE;
}
else if (def_state == OUTSIDE) {
@@ -1084,7 +1086,8 @@
while (pch_char (old) == '!');
if (R_do_defines) {
- fprintf (fp, outstate->after_newline + else_defined);
+ fprintf (fp, outstate->after_newline + else_defined,
+ R_do_defines);
if (ferror (fp))
write_fatal ();
def_state = IN_ELSE;
@@ -1122,7 +1125,8 @@
def_state = IN_IFDEF;
}
else if (def_state == IN_IFNDEF) {
- fprintf (fp, outstate->after_newline + else_defined);
+ fprintf (fp, outstate->after_newline + else_defined,
+ R_do_defines);
def_state = IN_ELSE;
}
if (ferror (fp))
--
Pete Buechler
Developer, SuSE Labs
address@hidden
http://www.suse.com/~peterb
-------------------------------------------------------
--
Pete Buechler
Developer, SuSE Labs
address@hidden
http://www.suse.com/~peterb
test1.txt
Description: Text document
test2.txt
Description: Text document
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Fwd: Serious bug in patch with --ifdef option,
Pete Buechler <=