RFR: 8261949: fileStream::readln returns incorrect line string
Daniel D.Daugherty
dcubed at openjdk.java.net
Thu Feb 18 16:23:43 UTC 2021
On Thu, 18 Feb 2021 12:31:29 GMT, Yang Yi <github.com+5010047+kelthuzadx at openjdk.org> wrote:
> When the last line does not contain a NEWLINE character, fileStream::readln would read
> truncated line string:
>
> $ cat file_content:
> AA
> BB
> CC<EOF>
>
> fileStream::readln result:
> "AA"
> "BB"
> "C"
>
> This patch address this problem, it works for Posix and Windows since the last character
> of these systems is always '\n'.
Changes requested by dcubed (Reviewer).
src/hotspot/share/utilities/ostream.cpp line 593:
> 591: ret = ::fgets(data, count, _file);
> 592: // Get rid of annoying \n char only if it presents, it works for Posix
> 593: // and Windows since the last character of these systems is always '\n'
s/of these/on these/
Please end the comment with a period.
src/hotspot/share/utilities/ostream.cpp line 595:
> 593: // and Windows since the last character of these systems is always '\n'
> 594: if (data[::strlen(data)-1] == '\n') {
> 595: data[::strlen(data)-1] = '\0';
Perhaps:
size_t last_char = ::strlen(data) - 1;
if (last_char >= 0 && data[last_char] == '\n') {
data[last_char] = '\0';
-------------
PR: https://git.openjdk.java.net/jdk/pull/2626
More information about the hotspot-runtime-dev
mailing list