-static inline void FD_CLR(int fd, fd_set *fdsetp) { fdsetp->flags[fd/16]&=~(1<<(fd%16)); }
-static inline void FD_SET(int fd, fd_set *fdsetp) { fdsetp->flags[fd/16]|=1<<(fd%16); }
-static inline int FD_ISSET(int fd, fd_set *fdsetp) { return fdsetp->flags[fd/16]&(1<<(fd%16)); }
+static inline void FD_CLR(int fd, fd_set *fdsetp) {
+ if(fd < 0 || fd > FD_SETSIZE) return;
+ fdsetp->flags[fd/16] &= (uint16_t) ((~1 << (fd%16))) & 0xFFFF;
+}
+static inline void FD_SET(int fd, fd_set *fdsetp) {
+ if(fd < 0 || fd > FD_SETSIZE) return;
+ fdsetp->flags[fd/16] |= (uint16_t) (1 << (fd%16));
+}
+static inline int FD_ISSET(int fd, fd_set *fdsetp) {
+ if(fd < 0 || fd > FD_SETSIZE) return 0;
+ return !!( fdsetp->flags[fd/16] & (1<<(fd%16)) );
+}