commit 3a48bac9e12e518894fe2700857f7e64d04c7f54
parent 8f63e22895647504086452440eea4774bc2ae551
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sat, 17 Aug 2024 11:38:04 +0200
fix warning & possible of wrong range check for key-value based parameter value lists
Diffstat:
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/source/jucePluginLib/parameterbinding.cpp b/source/jucePluginLib/parameterbinding.cpp
@@ -149,9 +149,9 @@ namespace pluginLib
for(uint32_t i=0; i<valueList.order.size(); ++i)
{
const auto value = valueList.orderToValue(i);
- if(value == ValueList::InvalidIndex)
+ if(value == ValueList::InvalidValue)
continue;
- if(i < range.getStart() || i > range.getEnd())
+ if(value < range.getStart() || value > range.getEnd())
continue;
const auto text = valueList.valueToText(value);
if(text.empty())
diff --git a/source/jucePluginLib/parametervaluelist.cpp b/source/jucePluginLib/parametervaluelist.cpp
@@ -22,17 +22,17 @@ namespace pluginLib
return texts[_value];
}
- uint32_t ValueList::orderToValue(const uint32_t _orderIndex) const
+ ParamValue ValueList::orderToValue(const uint32_t _orderIndex) const
{
if(_orderIndex >= order.size())
- return InvalidIndex;
+ return InvalidValue;
return order[_orderIndex];
}
const std::string& ValueList::orderToText(const uint32_t _orderIndex) const
{
const auto value = orderToValue(_orderIndex);
- if(value == InvalidIndex)
+ if(value == InvalidValue)
return g_empty;
return valueToText(value);
}
diff --git a/source/jucePluginLib/parametervaluelist.h b/source/jucePluginLib/parametervaluelist.h
@@ -4,20 +4,24 @@
#include <map>
#include <string>
#include <vector>
+#include <limits>
+
+#include "types.h"
namespace pluginLib
{
struct ValueList
{
static constexpr uint32_t InvalidIndex = 0xffffffff;
+ static constexpr ParamValue InvalidValue = std::numeric_limits<int>::min();
uint32_t textToValue(const std::string& _string) const;
const std::string& valueToText(const uint32_t _value) const;
- uint32_t orderToValue(uint32_t _orderIndex) const;
+ ParamValue orderToValue(uint32_t _orderIndex) const;
const std::string& orderToText(uint32_t _orderIndex) const;
std::vector<std::string> texts;
std::map<std::string, uint32_t> textToValueMap;
- std::vector<uint32_t> order;
+ std::vector<ParamValue> order;
};
}