[lld] r315495 - Return early if it fails to parse a hex string.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 11 12:30:39 PDT 2017
Author: ruiu
Date: Wed Oct 11 12:30:39 2017
New Revision: 315495
URL: http://llvm.org/viewvc/llvm-project?rev=315495&view=rev
Log:
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.
Modified:
lld/trunk/ELF/ScriptParser.cpp
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=315495&r1=315494&r2=315495&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Wed Oct 11 12:30:39 2017
@@ -867,10 +867,16 @@ static Optional<uint64_t> parseInt(Strin
// 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")) {
More information about the llvm-commits
mailing list