RFR: 8332400: isspace argument should be a valid unsigned char [v2]

Robert Toyonaga duke at openjdk.org
Tue Jun 11 18:07:10 UTC 2024


> ### Summary
> This change ensures we don't get undefined behavior when calling[`isspace`](https://pubs.opengroup.org/onlinepubs/007904975/functions/isspace.html).  `isspace` accepts an `int` argument that "the application shall ensure is a character representable as an unsigned char or equal to the value of the macro EOF.". 
> 
> Previously, there was no checking of the values passed to `isspace`. I've replaced direct calls with a new wrapper `os::is_space` that performs a range check and prevents the possibility of undefined behavior from happening. For instances outside of Hotspot, I've added casts to `unsigned char`. 
> 
> **Testing**
> - Added a new test in `test/hotspot/gtest/runtime/test_os.cpp` to check `os::is_space` is working correctly.
> - tier1

Robert Toyonaga has updated the pull request incrementally with one additional commit since the last revision:

  Replace wrapper with casts.

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/19567/files
  - new: https://git.openjdk.org/jdk/pull/19567/files/dabc185b..fe5e16e2

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=19567&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=19567&range=00-01

  Stats: 36 lines in 10 files changed: 0 ins; 20 del; 16 mod
  Patch: https://git.openjdk.org/jdk/pull/19567.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19567/head:pull/19567

PR: https://git.openjdk.org/jdk/pull/19567


More information about the core-libs-dev mailing list