Measure: initialize unit to nullptr, and don't dereference it if it is
nullptr.
NumberFormatterImpl::writeAffixes: U_ASSERT not-null, instead of
segfaulting for coding mistakes.
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Measure)
-Measure::Measure() {}
+Measure::Measure() : unit(nullptr) {}
Measure::Measure(const Formattable& _number, MeasureUnit* adoptedUnit,
UErrorCode& ec) :
}
Measure::Measure(const Measure& other) :
- UObject(other), unit(0) {
+ UObject(other), unit(nullptr) {
*this = other;
}
if (this != &other) {
delete unit;
number = other.number;
- unit = other.unit->clone();
+ if (other.unit != nullptr) {
+ unit = other.unit->clone();
+ } else {
+ unit = nullptr;
+ }
}
return *this;
}
int32_t NumberFormatterImpl::writeAffixes(const MicroProps& micros, FormattedStringBuilder& string,
int32_t start, int32_t end, UErrorCode& status) {
+ U_ASSERT(micros.modOuter != nullptr);
// Always apply the inner modifier (which is "strong").
int32_t length = micros.modInner->apply(string, start, end, status);
if (micros.padding.isValid()) {