Skip to content

Commit 25f5945

Browse files
committed
Add an fraction typein; be defensive about strncpy
1 parent 68e8ea3 commit 25f5945

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

include/sst/basic-blocks/params/ParamMetadata.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ struct ParamMetaData
202202
enum struct Features : uint64_t
203203
{
204204
SUPPORTS_MULTIPLICATIVE_MODULATION = 1 << 0,
205-
BELOW_ONE_IS_INVERSE_FRACTION = 1 << 1
205+
BELOW_ONE_IS_INVERSE_FRACTION = 1 << 1,
206+
ALLOW_FRACTIONAL_TYPEINS = 1 << 2
206207
};
207208
uint64_t features{0};
208209
ParamMetaData withFeature(Features f) const
@@ -858,8 +859,10 @@ struct ParamMetaData
858859
void toClapParamInfo(IsAClapParamInfo *info) const
859860
{
860861
info->id = id;
861-
strncpy(info->name, name.c_str(), stringSize);
862-
strncpy(info->module, groupName.c_str(), stringSize);
862+
strncpy(info->name, name.c_str(), stringSize - 2);
863+
info->name[stringSize - 1] = 0;
864+
strncpy(info->module, groupName.c_str(), stringSize - 2);
865+
info->module[stringSize - 1] = 0;
863866
info->min_value = minVal;
864867
info->max_value = maxVal;
865868
info->default_value = defaultVal;
@@ -1142,6 +1145,19 @@ inline std::optional<float> ParamMetaData::valueFromString(std::string_view v, s
11421145
else
11431146
r = 1.0 / uv;
11441147
}
1148+
else if ((features & (uint64_t)Features::ALLOW_FRACTIONAL_TYPEINS) &&
1149+
vs.find("/") != std::string::npos)
1150+
{
1151+
auto ps = vs.find("/");
1152+
auto num = vs.substr(0, ps);
1153+
auto den = vs.substr(ps + 1);
1154+
auto uv = std::stof(num);
1155+
auto dv = std::stof(den);
1156+
if (uv == 0 || dv == 0)
1157+
r = std::stof(std::string(v));
1158+
else
1159+
r = uv / dv;
1160+
}
11451161
else
11461162
{
11471163
r = std::stof(std::string(v));

0 commit comments

Comments
 (0)