Skip to content

Commit 2b55501

Browse files
y1yang0DamonFool
authored andcommitted
8261949: fileStream::readln returns incorrect line string
Reviewed-by: dcubed, dholmes
1 parent 539c80b commit 2b55501

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/hotspot/share/utilities/ostream.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,11 @@ char* fileStream::readln(char *data, int count ) {
589589
char * ret = NULL;
590590
if (_file != NULL) {
591591
ret = ::fgets(data, count, _file);
592-
//Get rid of annoying \n char
593-
data[::strlen(data)-1] = '\0';
592+
// Get rid of annoying \n char only if it is present.
593+
size_t len = ::strlen(data);
594+
if (len > 0 && data[len - 1] == '\n') {
595+
data[len - 1] = '\0';
596+
}
594597
}
595598
return ret;
596599
}

0 commit comments

Comments
 (0)