Skip to content

Commit

Permalink
cpp: fix broken handling of frame range negative step parsing for PCR…
Browse files Browse the repository at this point in the history
…E; switch step from size_t to long
  • Loading branch information
justinfx committed Oct 20, 2019
1 parent bd4d779 commit d5d6756
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cpp/frameset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void FrameSet::handleMatch(const internal::RangePatternMatch* match, Status* ok)
ok->clearError();

Frame start, end;
size_t step = 1;
long step = 1;

switch (num) {

Expand Down
8 changes: 4 additions & 4 deletions cpp/private/frameset_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ bool getRangePatternMatch(RangePatternMatch &match, const std::string &range) {
// Complex range: 1-10x2
static const char* s_pattern3 = R"(^(-?\d+)-(-?\d+)([:xy])(-?\d+)$)";

match.stepMod.clear();
match.step = 1;

#if HAVE_REGEX == 1
static const auto flags = std::regex_constants::optimize|std::regex_constants::ECMAScript;
static const std::regex s_rxRange1(s_pattern1, flags);
Expand All @@ -36,9 +39,6 @@ bool getRangePatternMatch(RangePatternMatch &match, const std::string &range) {

std::smatch submatch;

match.stepMod.clear();
match.step = 1;

if ( std::regex_match(range, submatch, s_rxRange1) ) {
match.matches = 2;
match.start = std::stol(submatch[1].str(), nullptr);
Expand All @@ -58,7 +58,7 @@ bool getRangePatternMatch(RangePatternMatch &match, const std::string &range) {
match.start = std::stol(submatch[1].str(), nullptr);
match.end = std::stol(submatch[2].str(), nullptr);
match.stepMod = submatch[3].str();
match.step = std::stoul(submatch[4].str(), nullptr);
match.step = std::stol(submatch[4].str(), nullptr);
return true;
}
#else
Expand Down
2 changes: 1 addition & 1 deletion cpp/private/frameset_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct RangePatternMatch { ;
Frame start;
Frame end;
std::string stepMod;
size_t step;
long step;
};

// Regular expression patterns for matching frame set strings.
Expand Down
10 changes: 5 additions & 5 deletions cpp/ranges/ranges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace fileseq {


Range::Range(long start, long end, int step)
Range::Range(long start, long end, long step)
: m_start(start)
, m_end(end)
, m_step(step)
Expand Down Expand Up @@ -103,7 +103,7 @@ bool Range::contains(long value) const {
}


long Range::closestInRange(long value, long start, long end, int step) const {
long Range::closestInRange(long value, long start, long end, long step) const {
// Possibly clamp the value if it is outside the range
if (end >= start) {
if (value < start) {
Expand Down Expand Up @@ -137,7 +137,7 @@ long Range::value(size_t idx, Status* ok) const {
// Calculate the value as an offset from the start
long l_start = start();
long l_end = end();
int l_step = step();
long l_step = step();

long val = l_start + (l_step * idx);

Expand Down Expand Up @@ -303,7 +303,7 @@ bool predDecRangeDone(long val, long end) {
return val >= end;
}

void Ranges::appendUnique(long start, long end, int step) {
void Ranges::appendUnique(long start, long end, long step) {
if (step == 0) {
// Invalid step. Do nothing.
return;
Expand Down Expand Up @@ -451,7 +451,7 @@ void Ranges::normalized(Ranges &outRanges, bool invert) const {
long start = 0;
long end = 0;
long current = 0;
int step = 0;
long step = 0;
bool keepValue = false;
size_t pending = 0;

Expand Down
14 changes: 7 additions & 7 deletions cpp/ranges/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RangeIterator {
// Advance to the next value.
bool next();

// Returns whether the interator points to a valid range
// Returns whether the iterator points to a valid range
bool isValid() const { return m_range != NULL; }

private:
Expand All @@ -58,7 +58,7 @@ class Range {
// If step value == 0, it will automatically default
// to a propert increment depending on whether start is
// less than or greather than end.
Range(long start, long end, int step=0);
Range(long start, long end, long step=0);

virtual ~Range() {}

Expand All @@ -77,7 +77,7 @@ class Range {
long end() const;

// returns the stepping value used in the range
int step() const { return m_step; }
long step() const { return m_step; }

// returns the smallest value in the range
long min() const { return (start() < end() ? start() : end()); }
Expand Down Expand Up @@ -122,12 +122,12 @@ class Range {
// closestInRange finds the closest valid value within the range,
// to a given value. Values outside the range are clipped to either
// the range min or max.
long closestInRange(long value, long start, long end, int step=0) const;
long closestInRange(long value, long start, long end, long step=0) const;

private:
long m_start;
long m_end;
int m_step;
long m_step;

mutable long m_cachedEnd;
mutable bool m_isEndCached;
Expand Down Expand Up @@ -221,14 +221,14 @@ class Ranges {
// to the total range list.
// Values in new range may duplicate values in
// existing ranges.
void append(long start, long end, int step=0) {
void append(long start, long end, long step=0) {
m_blocks.push_back(new Range(start, end, step));
}

// creates and adds another range of values
// to the total range list. Only unique values from the
// given range are appended to the total range.
void appendUnique(long start, long end, int step=0);
void appendUnique(long start, long end, long step=0);

// returns true if a given value is a valid
// value within the total range.
Expand Down

0 comments on commit d5d6756

Please sign in to comment.