Skip to content

Commit ed64f06

Browse files
committed
posix_sockets.c: Fix 16 bit integer compilation errors
1 parent 33d1fd2 commit ed64f06

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

sys/posix/sockets/posix_sockets.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ int setsockopt(int socket, int level, int option_name, const void *option_value,
11211121
#ifdef POSIX_SETSOCKOPT
11221122
socket_t *s;
11231123
struct timeval *tv;
1124-
const uint32_t max_timeout_secs = UINT32_MAX / (1000 * 1000);
1124+
const uint32_t max_timeout_secs = UINT32_MAX / US_PER_SEC;
11251125

11261126
if (level != SOL_SOCKET
11271127
|| option_name != SO_RCVTIMEO) {
@@ -1144,10 +1144,18 @@ int setsockopt(int socket, int level, int option_name, const void *option_value,
11441144

11451145
tv = (struct timeval *) option_value;
11461146

1147+
#if MODULE_AVR8_COMMON
1148+
/* tv_sec is uint32_t, so never negative */
1149+
if (tv->tv_usec < 0) {
1150+
errno = EINVAL;
1151+
return -1;
1152+
}
1153+
#else /* ! MODULE_AVR8_COMMON */
11471154
if (tv->tv_sec < 0 || tv->tv_usec < 0) {
11481155
errno = EINVAL;
11491156
return -1;
11501157
}
1158+
#endif /* ! MODULE_AVR8_COMMON */
11511159

11521160
if ((uint32_t)tv->tv_sec > max_timeout_secs
11531161
|| ((uint32_t)tv->tv_sec == max_timeout_secs && (uint32_t)tv->tv_usec > UINT32_MAX - max_timeout_secs * 1000 * 1000)) {

0 commit comments

Comments
 (0)