Skip to content

Commit

Permalink
Fix for TSAN failure, due to suspected lack of string NULL-terminator.
Browse files Browse the repository at this point in the history
Instead of relying on the char buffer being correctly NULL-terminated, we use the read length returned from `read()`.

PiperOrigin-RevId: 393109560
Change-Id: Icd37f7a1b9d168c81a104f8b3e92fb0fa661293f
  • Loading branch information
tomwardio authored and lanctot committed Aug 26, 2021
1 parent 2a5d3e4 commit 38941de
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions open_spiel/bots/uci/uci_bot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ std::string UCIBot::Read(bool wait) const {
fd_set fds;
FD_ZERO(&fds);
FD_SET(input_fd_, &fds);
timeval timeout = {1, 0}; // 1 second timeout.
timeval timeout = {5, 0}; // 5 second timeout.

int ready_fd = select(/*nfds=*/input_fd_ + 1,
/*readfds=*/&fds,
Expand All @@ -261,7 +261,7 @@ std::string UCIBot::Read(bool wait) const {
SpielFatalError("Failed to read from uci sub-process");
}
if (ready_fd == 0) {
SpielFatalError("Response from uci sub-process not received on time");
SpielFatalError("Response from uci sub-process not received in time");
}
if (ioctl(input_fd_, FIONREAD, &count) == -1) {
SpielFatalError("Failed to read input size.");
Expand All @@ -273,7 +273,7 @@ std::string UCIBot::Read(bool wait) const {
if (read(input_fd_, buff, count) != count) {
SpielFatalError("Read wrong number of bytes");
}
response = buff;
response.assign(buff, count);
free(buff);
return response;
}
Expand Down

0 comments on commit 38941de

Please sign in to comment.