Merge pull request #295 from pabigot/pr/20190530b

linux_tcp/poll: fix undefined behavior in select
This commit is contained in:
Emiel Bruijntjes 2019-06-19 10:42:39 +02:00 committed by GitHub
commit c328b93f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -106,8 +106,11 @@ public:
*/
bool active(bool block)
{
// accommodate restrict qualifier on fd_set params
fd_set set2 = _set;
// wait for the socket
if (block) return select(_socket + 1, &_set, &_set, nullptr, nullptr) > 0;
if (block) return select(_socket + 1, &_set, &set2, nullptr, nullptr) > 0;
// we do not want to block, so we use a small timeout
struct timeval timeout;
@ -116,7 +119,7 @@ public:
timeout.tv_sec = timeout.tv_usec = 0;
// no timeout at all
return select(_socket + 1, &_set, &_set, nullptr, &timeout) > 0;
return select(_socket + 1, &_set, &set2, nullptr, &timeout) > 0;
}
};
@ -124,4 +127,3 @@ public:
* End of namespace
*/
}