From 4092016b7ba6996d228892241bef1b0e4a8120e3 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 11 Oct 2017 19:30:39 +0000 Subject: [PATCH] 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 --- lld/ELF/ScriptParser.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index 7c8e260c576c..5582ce672fbf 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -867,10 +867,16 @@ static Optional 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")) {