-
Notifications
You must be signed in to change notification settings - Fork 15.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protoc: fix consistency with parsing very large decimal numbers #10555
Merged
fowles
merged 11 commits into
protocolbuffers:main
from
jhump:jh/fix-consistency-with-very-large-decimal-numbers
Sep 15, 2022
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2270d3f
allow excessively large int literal values (that would otherwise over…
jhump 87f24e4
add allowed ranges to error messages
jhump 4e54ec2
change format of int range in error message; use macro to make DRY
jhump 35dd193
add test to verify parsing of extremely large decimal integers to dou…
jhump 4c69337
use template instead of macro
jhump 7702355
address latest review comments
jhump 0bc90b1
put helpers into anon namespace
jhump f82be68
avoid possible exception; error if octal or hex literal that is too l…
jhump d6acffb
use normal conditional
jhump 0362a12
initialize var to avoid undefined return val
jhump 7e745c4
oops, fix name: LOG -> GOOGLE_LOG
jhump File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1002,9 +1002,19 @@ bool Tokenizer::ParseInteger(const std::string& text, uint64_t max_value, | |
} | ||
|
||
double Tokenizer::ParseFloat(const std::string& text) { | ||
double result; | ||
jhump marked this conversation as resolved.
Show resolved
Hide resolved
|
||
GOOGLE_LOG_IF(DFATAL, | ||
!TryParseFloat(text, &result)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hate side effected in LOG statements, do you mind switching this to the more straight forward:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
<< " Tokenizer::ParseFloat() passed text that could not have been" | ||
" tokenized as a float: " | ||
<< absl::CEscape(text); | ||
return result; | ||
} | ||
|
||
bool Tokenizer::TryParseFloat(const std::string& text, double* result) { | ||
const char* start = text.c_str(); | ||
char* end; | ||
double result = NoLocaleStrtod(start, &end); | ||
*result = NoLocaleStrtod(start, &end); | ||
|
||
// "1e" is not a valid float, but if the tokenizer reads it, it will | ||
// report an error but still return it as a valid token. We need to | ||
|
@@ -1020,12 +1030,7 @@ double Tokenizer::ParseFloat(const std::string& text) { | |
++end; | ||
} | ||
|
||
GOOGLE_LOG_IF(DFATAL, | ||
static_cast<size_t>(end - start) != text.size() || *start == '-') | ||
<< " Tokenizer::ParseFloat() passed text that could not have been" | ||
" tokenized as a float: " | ||
<< absl::CEscape(text); | ||
return result; | ||
return static_cast<size_t>(end - start) == text.size() && *start != '-'; | ||
} | ||
|
||
// Helper to append a Unicode code point to a string as UTF8, without bringing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put this here, instead of just relying on the branch below, because I think an octal literal would likely be successfully parsed by
ParseFloat
, but incorrectly interpreted as decimal.