aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2016-11-25 20:36:06 +0800
committerYoichi Hirai <i@yoichihirai.com>2016-11-25 20:36:06 +0800
commite136ec87041cce9d8d472e45f4dfbed9a8d02469 (patch)
treebcb1e74e7fd6a4705e7e28c612d3be0d43094fd6 /libsolidity
parentaaf58a8c4e802b1c3c4098066e0788e55600660a (diff)
downloaddexon-solidity-e136ec87041cce9d8d472e45f4dfbed9a8d02469.tar.gz
dexon-solidity-e136ec87041cce9d8d472e45f4dfbed9a8d02469.tar.zst
dexon-solidity-e136ec87041cce9d8d472e45f4dfbed9a8d02469.zip
ast: string literals that are not valid UTF are not convertible to strings
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/ast/Types.cpp9
-rw-r--r--libsolidity/ast/Types.h2
2 files changed, 10 insertions, 1 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index b7de3646..002ad657 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -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)
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index b713a7c0..72640a1c 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -425,6 +425,8 @@ public:
virtual std::string toString(bool) const override;
virtual TypePointer mobileType() const override;
+ bool isValidUTF8() const;
+
std::string const& value() const { return m_value; }
private: