Skip to content

Commit b8cc6c8

Browse files
committed
reset plain array size to 0
1 parent c6c0800 commit b8cc6c8

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎Framework/Core/include/Framework/Variant.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class Variant
322322

323323
template <typename T>
324324
requires(!is_specialization_v<T, std::vector>)
325-
Variant(T value) : mType{variant_trait_v<T>}, mSize{1}
325+
Variant(T value) : mType{variant_trait_v<T>}
326326
{
327327
variant_helper<decltype(value)>::set(&mStore, value);
328328
}
@@ -403,7 +403,6 @@ class Variant
403403
*this = Variant(value, size);
404404
}
405405

406-
/// FIXME: set for vector of strings is not used anywhere, why?
407406
template <typename T>
408407
void set(std::vector<T>& values)
409408
requires(std::is_pod_v<T> || std::is_same_v<T, std::string>)
@@ -429,7 +428,7 @@ class Variant
429428
LabeledArray<int>, LabeledArray<float>, LabeledArray<double>, LabeledArray<std::string>>::type;
430429
storage_t mStore;
431430
VariantType mType = VariantType::Unknown;
432-
size_t mSize = 0;
431+
size_t mSize = 1;
433432
};
434433

435434
inline Variant emptyDict() { return Variant(VariantType::Dict); }

‎Framework/Core/src/Variant.cxx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ Variant::Variant(VariantType type) : mType{type}
154154
// by creating a default stored object upfront
155155
if (!visitStoredObject(mType, [this]<typename T>() { new (&mStore) T{}; })) {
156156
std::memset(&mStore, 0, sizeof(mStore));
157+
switch (type) {
158+
case VariantType::ArrayBool:
159+
case VariantType::ArrayInt:
160+
case VariantType::ArrayFloat:
161+
case VariantType::ArrayDouble:
162+
case VariantType::ArrayString:
163+
mSize = 0; // empty plain array has size 0
164+
break;
165+
default:
166+
break;
167+
}
157168
}
158169
}
159170

0 commit comments

Comments
 (0)