diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2012-02-16 10:04:57 +0900 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2012-02-16 10:04:57 +0900 |
commit | b67f88a7d6322a293ac3e3be9d6df9f358509221 (patch) | |
tree | 099f6ef399204a0aadfd31fcd6f7494267901dfa /src | |
parent | aaa766acf7596eb4de7afe6ae0121335f4fd05da (diff) |
Valid handle_t is never NULL
poll_t and select_t polling mechanism convert fd into void*.
When fd 0 was converted NULL pointer resulted. Fixed.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/fd.hpp | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -35,19 +35,37 @@ namespace xs #if defined _MSC_VER &&_MSC_VER <= 1400 typedef UINT_PTR fd_t; enum {retired_fd = (fd_t)(~0)}; - inline void *fdtoptr (fd_t fd_) {return (void*) fd_;} - inline fd_t ptrtofd (void *ptr_) {return (fd_t) ptr_;} + inline void *fdtoptr (fd_t fd_) + { + return (void*) (fd_ + 1); + } + inline fd_t ptrtofd (void *ptr_) + { + return ((fd_t) ptr_) - 1; + } #else typedef SOCKET fd_t; enum {retired_fd = INVALID_SOCKET}; - inline void *fdtoptr (fd_t fd_) {return (void*) fd_;} - inline fd_t ptrtofd (void *ptr_) {return (fd_t) ptr_;} + inline void *fdtoptr (fd_t fd_) + { + return (void*) (fd_ + 1); + } + inline fd_t ptrtofd (void *ptr_) + { + return ((fd_t) ptr_) - 1; + } #endif #else typedef int fd_t; enum {retired_fd = -1}; - inline void *fdtoptr (fd_t fd_) {return (void*) fd_;} - inline fd_t ptrtofd (void *ptr_) {return (int) ((char*) ptr_ - (char*) 0);} + inline void *fdtoptr (fd_t fd_) + { + return (void*) (fd_ + 1); + } + inline fd_t ptrtofd (void *ptr_) + { + return ((int) ((char*) ptr_ - (char*) 0)) - 1; + } #endif } |