From 5922d12960110b75e8fe7f8a7ea1a1d6a5bec708 Mon Sep 17 00:00:00 2001 From: Tsige Solomon Date: Thu, 15 Jun 2023 08:17:16 -0700 Subject: Bug fix PiperOrigin-RevId: 540586646 Change-Id: Iac1e133647fbaa5036ac9ef7322f9af5886c658e --- absl/flags/marshalling.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'absl/flags/marshalling.cc') diff --git a/absl/flags/marshalling.cc b/absl/flags/marshalling.cc index 50b7b331..dc69754f 100644 --- a/absl/flags/marshalling.cc +++ b/absl/flags/marshalling.cc @@ -70,8 +70,10 @@ bool AbslParseFlag(absl::string_view text, bool* dst, std::string*) { // puts us in base 16. But leading 0 does not put us in base 8. It // caused too many bugs when we had that behavior. static int NumericBase(absl::string_view text) { - const bool hex = (text.size() >= 2 && text[0] == '0' && - (text[1] == 'x' || text[1] == 'X')); + if (text.empty()) return 0; + size_t num_start = (text[0] == '-' || text[0] == '+') ? 1 : 0; + const bool hex = (text.size() >= num_start + 2 && text[num_start] == '0' && + (text[num_start + 1] == 'x' || text[num_start + 1] == 'X')); return hex ? 16 : 10; } -- cgit v1.2.3