summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Persch <chpe@src.gnome.org>2019-04-20 19:41:46 +0200
committerChristian Persch <chpe@src.gnome.org>2019-04-20 19:41:46 +0200
commit8afa5e46905492779027ed2c04e8a63e30cd74df (patch)
tree54b4607723e00e5bf325c18d363494a567dfeb02
parentd4da2ac7417c710bc7e9824062ab09d1187e815a (diff)
downloadvte-0.57.0.tar.gz
parser: glue: Correct parameter collection0.57.0
If the minimum value is greater than the maximum_value (which can happen e.g. when the minimum is 1 and the maximum is m_column_count - cursor.column), the parameter collection should return the minimum value, not the maximum value.
-rw-r--r--src/parser-glue.hh11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/parser-glue.hh b/src/parser-glue.hh
index 9c23a0a3..7c9aa5d1 100644
--- a/src/parser-glue.hh
+++ b/src/parser-glue.hh
@@ -273,7 +273,7 @@ public:
* Returns: the value of the parameter at index @idx, or @default_v if
* the parameter at this index has default value, or the index
* is out of bounds. The returned value is clamped to the
- * range @min_v..@max_v.
+ * range @min_v..@max_v (or returns min_v, if min_v > max_v).
*/
inline constexpr int param(unsigned int idx,
int default_v,
@@ -281,7 +281,8 @@ public:
int max_v) const noexcept
{
auto v = param(idx, default_v);
- return std::min(std::max(v, min_v), max_v);
+ // not using std::clamp() since it's not guaranteed that min_v <= max_v
+ return std::max(std::min(v, max_v), min_v);
}
/* param_nonfinal:
@@ -372,7 +373,8 @@ public:
*
* Collects one final parameter.
*
- * Returns: the parameter value clamped to the @min_v .. @max_v range,
+ * Returns: the parameter value clamped to the @min_v .. @max_v range (or @min_v,
+ * if min_v > max_v),
* or @default_v if the parameter has default value or is not a final parameter
*/
inline constexpr int collect1(unsigned int idx,
@@ -381,7 +383,8 @@ public:
int max_v) const noexcept
{
int v = __builtin_expect(idx < size(), 1) ? vte_seq_arg_value_final(m_seq->args[idx], default_v) : default_v;
- return std::min(std::max(v, min_v), max_v);
+ // not using std::clamp() since it's not guaranteed that min_v <= max_v
+ return std::max(std::min(v, max_v), min_v);
}
/* collect_subparams: