ast: string literals that are not valid UTF are not convertible to strings

This commit is contained in:
Yoichi Hirai committed 2016-11-25 13:36:06 +01:00
1 parent aaf58a8c4e
commit e136ec8704
4 files changed
+12 -3

No files matched your search

+8 -1
View File
@@ -879,7 +879,8 @@ bool StringLiteralType::isImplicitlyConvertibleTo(Type const& _convertTo) const
else if (auto arrayType = dynamic_cast<ArrayType const*>(&_convertTo))
return
arrayType->isByteArray() &&
!(arrayType->dataStoredIn(DataLocation::Storage) && arrayType->isPointer());
!(arrayType->dataStoredIn(DataLocation::Storage) && arrayType->isPointer()) &&
!(arrayType->isString() && !isValidUTF8());
else
return false;
}
@@ -906,6 +907,12 @@ TypePointer StringLiteralType::mobileType() const
return make_shared<ArrayType>(DataLocation::Memory, true);
}
bool StringLiteralType::isValidUTF8() const
{
size_t dontCare {};
return dev::validate(m_value, dontCare);
}
shared_ptr<FixedBytesType> FixedBytesType::smallestTypeForLiteral(string const& _literal)
{
if (_literal.length() <= 32)