aboutsummaryrefslogtreecommitdiff
path: root/llvm/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
commit815433587cc62a5b0f361dd11bbf6d846c9ee50c (patch)
tree7b95f60b3e11f4e754c34199adee0f2c7b3a79ec /llvm/lib/Support/YAMLTraits.cpp
parentc3d9db23368dda199704a9f39b9cbe551f1992f8 (diff)
downloadllvm-815433587cc62a5b0f361dd11bbf6d846c9ee50c.zip
llvm-815433587cc62a5b0f361dd11bbf6d846c9ee50c.tar.gz
llvm-815433587cc62a5b0f361dd11bbf6d846c9ee50c.tar.bz2
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. llvm-svn: 205839
Diffstat (limited to 'llvm/lib/Support/YAMLTraits.cpp')
-rw-r--r--llvm/lib/Support/YAMLTraits.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index 38f3ec7..3b4bb7d 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/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);