8371762: Incorrect use of checked_cast in Arguments::process_settings_file #28283
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.
JDK-8313882 introduced a
checked_castwhen to silence the Wconversion warnings when we store anintin achar. The problem is that the assumption that the value in theintwe get fromgetcis compatible withcharis incorrect.The specification for
getcis that it returns eitherEOFor the next readunsigned charconverted to anint. This means we have the possible values of{EOF, 0-255}, we always check forEOFfirst, so we end up only having{0-255}as the possible values. (While a char has the possible values of{-128-127}.)So first the problem with
checked_cast(which ensures that the type roundtrip is lossless) will end up converting any value in{128-255}to{-128, -1}which when converted back to anintis{-128, -1}and not{128-255}.The thing is that this is not a problem except for the assert as we do not care if the conversion roundtrip is lossless. We only want to reinterpret the value as a
char, and never try to regain the unsigned representation converted to anintthatgetcuses.Another issue with keeping the value inside an
intwhich could lead to bugs in the future is that when we use it in equality comparison agains acharwe will encounter an integer promotion of thecharwhich will lead to surprising incorrect results if the character is non-ascii.Currently we have no such comparisons of this
intvs a non-ascii character. So the only issue is the assert insidechecked_castwhich will trigger if the settings file contains a non-ascii character.I suggest we convert the return value from
getcto acharafter we have check forEOFand before we use it as a character.It is worth noting that the
(unsigned char)casts for the calls intoisspace(introduced by JDK-8332400) is very important to get the correct value for itsintinput parameter. (So we get the correct non-sign extended castchar -> unsigned char -> int.) That issue mentions the possibility of introducing our ownisspace(suggestion wasos::isspace) which we could overload the different types and do the correct thing with bound checks. This might be something we want to revisit.isspacespecification:Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28283/head:pull/28283$ git checkout pull/28283Update a local copy of the PR:
$ git checkout pull/28283$ git pull https://git.openjdk.org/jdk.git pull/28283/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28283View PR using the GUI difftool:
$ git pr show -t 28283Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28283.diff
Using Webrev
Link to Webrev Comment