#261 rangeset_add of empty range works - bad!

development
closed-fixed
nobody
Program (402)
5
2003-05-02
2003-04-28
Tony Balinski
No

I have noticed zero-length ranges in some rangesets
from time to time. This invalidates a basic assuption
about the rangeset functionality - that all ranges contain
something. (This goes with the coalescing of ranges in
sets, and the fact that you can remove a range using its
extent without leaving two zero-length ranges at either
end.)
It turns out I never controlled the ranges coming in via
macro functio rangeset_add()!
Here's a fix to apply to rangeset.c:
In RangesetAddFromTo() AND RangesetRemoveFromTo
() (for good measure), add the following just after the
local variable declarations:

if (start > end) {
i = start; /* quietly sort the positions */
start = end;
end = i;
}
else if (start == end) {
return p->n_ranges; /* no-op - empty range == no
range */
}

Discussion

  • Eddy De Greef
    Eddy De Greef
    2003-05-02

    • status: open --> closed
     
  • Eddy De Greef
    Eddy De Greef
    2003-05-02

    Logged In: YES
    user_id=73597

    I've committed the new rangeset API patch with these fixes
    included.

     
  • Eddy De Greef
    Eddy De Greef
    2003-05-02

    • milestone: --> development
    • status: closed --> closed-fixed