Bug 93810

Summary: Method extractPair(String, char, int[]) in Patcher.java fails on single number in range
Product: [Eclipse Project] Platform Reporter: Martin Burger <m>
Component: CompareAssignee: Andre Weinand <andre_weinand>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.0.2   
Target Milestone: 3.1 M7   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch for Patcher.java none

Description Martin Burger CLA 2005-05-05 12:27:47 EDT
The header of a hunk of an unified diff shows one area where the files differ:

@@ from-file-range to-file-range @@

See:
http://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html#Detailed%20Unified

More precisely: @@ -oldStart,oldLength +newStart,newLength @@

If the length is 1, then only the start value is included in the header.

E.g. "@@ -5 +5 @@" instead of "@@ -5,1 +5,1 @@".

The method extractPair(String, char, int[]) in Patcher.java tries to handle
this, but the two values of the array "pair" are swaped:

    588: pair[0]= 1;
    589: pair[1]= Integer.parseInt(line.substring(comma+1));

Executing this code, the value of pair will be [1,5], but it has to be [5,1].

Just swap the assignments:

    588: pair[0]= Integer.parseInt(line.substring(comma+1));
    589: pair[1]= 1;

This fixes the issue.
Comment 1 Martin Burger CLA 2005-05-05 12:31:27 EDT
Created attachment 20746 [details]
Patch for Patcher.java

This patch swaps the two assignments of pair.
Comment 2 Andre Weinand CLA 2005-05-06 05:49:17 EDT
Thanks for the patch!
However, I'm somewhat reluctant to use it because I have yet to find the part of the specification saying 
that "If the length is 1, then only the start value is included in the header".

BTW, my code

} else {
     pair[1]= Integer.parseInt(line.substring(comma+1))

works only by accident because the value of comma happens to be -1 in the else case, which results in 
a
     line.substring(-1+1)
This is not wrong but slightly bogus...
Comment 3 Andre Weinand CLA 2005-05-06 08:35:41 EDT
Do you know how to create a patch that uses the "@@ -5 +5 @@" syntax?
Comment 4 Martin Burger CLA 2005-05-06 08:52:23 EDT
Take a file with one changed line. Create an unified diff with no context lines
as follows:


    # diff -U 0 orig_short.txt changed_short.txt
    --- orig_short.txt      Fri May  6 01:46:07 2005
    +++ changed_short.txt   Fri May  6 14:44:19 2005
    @@ -5 +5 @@
    -[5] amet,
    +[5] amet, CHANGED LINE


The "specification" can be found in the source code of the Diffutils:

File: diffutils-2.8.1/src/context.c
Function: print_unidiff_number_range
Line: 274

    fprintf (outfile, trans_b < trans_a ? "%ld,0" : "%ld", trans_b);
Comment 5 Andre Weinand CLA 2005-05-06 10:55:20 EDT
released patch for N20050507