diff options
author | Tsige Solomon <tsige@google.com> | 2023-06-15 08:17:16 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-06-15 08:18:26 -0700 |
commit | 5922d12960110b75e8fe7f8a7ea1a1d6a5bec708 (patch) | |
tree | 06ebe07380a05dccd78c4f75bf9af57a0ba6581c /absl/flags/marshalling.cc | |
parent | 4a82a1f4699348673426e255bbf8f8d8fadc7682 (diff) | |
download | abseil-5922d12960110b75e8fe7f8a7ea1a1d6a5bec708.tar.gz abseil-5922d12960110b75e8fe7f8a7ea1a1d6a5bec708.tar.bz2 abseil-5922d12960110b75e8fe7f8a7ea1a1d6a5bec708.zip |
Bug fix
PiperOrigin-RevId: 540586646
Change-Id: Iac1e133647fbaa5036ac9ef7322f9af5886c658e
Diffstat (limited to 'absl/flags/marshalling.cc')
-rw-r--r-- | absl/flags/marshalling.cc | 6 |
1 files changed, 4 insertions, 2 deletions
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; } |