Merge pull request #826 from axic/utf8-check

AST printer: do not output invalid UTF8 sequences
This commit is contained in:
chriseth
2016-08-10 16:31:27 +02:00
committed by GitHub
4 changed files with 128 additions and 1 deletions
+11
View File
@@ -26,6 +26,7 @@
#include <libdevcore/CommonIO.h>
#include <libdevcore/CommonData.h>
#include <libdevcore/SHA3.h>
#include <libdevcore/UTF8.h>
#include <libsolidity/interface/Utils.h>
#include <libsolidity/ast/AST.h>
@@ -852,6 +853,16 @@ bool StringLiteralType::operator==(const Type& _other) const
return m_value == dynamic_cast<StringLiteralType const&>(_other).m_value;
}
std::string StringLiteralType::toString(bool) const
{
size_t invalidSequence;
if (!dev::validate(m_value, invalidSequence))
return "literal_string (contains invalid UTF-8 sequence at position " + dev::toString(invalidSequence) + ")";
return "literal_string \"" + m_value + "\"";
}
TypePointer StringLiteralType::mobileType() const
{
return make_shared<ArrayType>(DataLocation::Memory, true);
+1 -1
View File
@@ -419,7 +419,7 @@ public:
virtual bool canLiveOutsideStorage() const override { return false; }
virtual unsigned sizeOnStack() const override { return 0; }
virtual std::string toString(bool) const override { return "literal_string \"" + m_value + "\""; }
virtual std::string toString(bool) const override;
virtual TypePointer mobileType() const override;
std::string const& value() const { return m_value; }