8261949: fileStream::readln returns incorrect line string

Reviewed-by: dcubed, dholmes
This commit is contained in:
Yang Yi 2021-02-22 02:22:07 +00:00 committed by Jie Fu
parent 539c80bfda
commit 2b55501519

View file

@ -589,8 +589,11 @@ char* fileStream::readln(char *data, int count ) {
char * ret = NULL;
if (_file != NULL) {
ret = ::fgets(data, count, _file);
//Get rid of annoying \n char
data[::strlen(data)-1] = '\0';
// Get rid of annoying \n char only if it is present.
size_t len = ::strlen(data);
if (len > 0 && data[len - 1] == '\n') {
data[len - 1] = '\0';
}
}
return ret;
}