summaryrefslogtreecommitdiff
path: root/lib/Support/YAMLTraits.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-04-09 07:56:27 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-04-09 07:56:27 +0000
commit7184f49f400fea6d3f57566ba0749d6de53310cf (patch)
treef10039021864f6d61ad748d6a5a262562ae28e0b /lib/Support/YAMLTraits.cpp
parent144ffd6624c040217423aa46e9b5dc2dc0922326 (diff)
downloadllvm-7184f49f400fea6d3f57566ba0749d6de53310cf.tar.gz
llvm-7184f49f400fea6d3f57566ba0749d6de53310cf.tar.bz2
llvm-7184f49f400fea6d3f57566ba0749d6de53310cf.tar.xz
YAMLIO: Encode ambiguous hex strings explicitly
YAMLIO would turn a BinaryRef into the string 0000000004000000. However, the leading zero causes parsers to interpret it as being an octal number instead of a hexadecimal one. Instead, escape such strings as needed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205839 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/YAMLTraits.cpp')
-rw-r--r--lib/Support/YAMLTraits.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/Support/YAMLTraits.cpp b/lib/Support/YAMLTraits.cpp
index 38f3ec7c7f..3b4bb7dbc9 100644
--- a/lib/Support/YAMLTraits.cpp
+++ b/lib/Support/YAMLTraits.cpp
@@ -561,8 +561,11 @@ void Output::scalarString(StringRef &S) {
this->outputUpToEndOfLine("''");
return;
}
+ bool isOctalString = S.front() == '0' &&
+ S.find_first_not_of('0') != StringRef::npos &&
+ !S.startswith_lower("0x");
if (S.find_first_not_of(ScalarSafeChars) == StringRef::npos &&
- !isspace(S.front()) && !isspace(S.back())) {
+ !isspace(S.front()) && !isspace(S.back()) && !isOctalString) {
// If the string consists only of safe characters, print it out without
// quotes.
this->outputUpToEndOfLine(S);