diff options
author | Rui Ueyama <ruiu@google.com> | 2017-10-11 19:30:39 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2017-10-11 19:30:39 +0000 |
commit | 4092016b7ba6996d228892241bef1b0e4a8120e3 (patch) | |
tree | e869e65a07ccb7067509c1ca5a0ad4c3697aa516 /lld/ELF/ScriptParser.cpp | |
parent | c530f497b89aff0f917fb6942fd65032f30d9381 (diff) | |
download | bcm5719-llvm-4092016b7ba6996d228892241bef1b0e4a8120e3.tar.gz bcm5719-llvm-4092016b7ba6996d228892241bef1b0e4a8120e3.zip |
Return early if it fails to parse a hex string.
This patch doesn't change the behavior of the program because it
would eventually return None at end of the function. But it is
better to return None early if we know it will eventually happen.
llvm-svn: 315495
Diffstat (limited to 'lld/ELF/ScriptParser.cpp')
-rw-r--r-- | lld/ELF/ScriptParser.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index 7c8e260c576..5582ce672fb 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -867,10 +867,16 @@ static Optional<uint64_t> parseInt(StringRef Tok) { // Hexadecimal uint64_t Val; - if (Tok.startswith_lower("0x") && to_integer(Tok.substr(2), Val, 16)) + if (Tok.startswith_lower("0x")) { + if (!to_integer(Tok.substr(2), Val, 16)) + return None; return Val; - if (Tok.endswith_lower("H") && to_integer(Tok.drop_back(), Val, 16)) + } + if (Tok.endswith_lower("H")) { + if (!to_integer(Tok.drop_back(), Val, 16)) + return None; return Val; + } // Decimal if (Tok.endswith_lower("K")) { |