[vte/vte-0-56] parser: glue: Correct parameter collection
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/vte-0-56] parser: glue: Correct parameter collection
- Date: Sat, 20 Apr 2019 17:45:31 +0000 (UTC)
commit 9a079492ea698f573dfc7129f1c79e4a865803b4
Author: Christian Persch <chpe src gnome org>
Date: Sat Apr 20 19:41:46 2019 +0200
parser: glue: Correct parameter collection
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.
(cherry picked from commit 8afa5e46905492779027ed2c04e8a63e30cd74df)
src/parser-glue.hh | 11 +++++++----
1 file 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:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]