Skip to content

Commit b0de663

Browse files
committed
pico w: setsockopt: Fix sense of disable vs enable
memcmp() returns -1, 0 or 1 to denote the relative ordering of the two buffers. So, the computation would actually set `enable = 0` in the case where `value` had the same bits set as "one" and `enable = 1` in the case where `value` had any other bits. By changing the compared buffer to be `zero`, `enable` gets a true value whenever the value is NOT exactly 0 (e.g., it's 1, 7, -1, ...), correcting the sense of enable vs disable. Thanks to @anecdata for testing and finding this problem, which previously would have affected the nodelay flag as well.
1 parent a6b1292 commit b0de663

File tree

1 file changed

+2
-2
lines changed
  • ports/raspberrypi/common-hal/socketpool

1 file changed

+2
-2
lines changed

ports/raspberrypi/common-hal/socketpool/Socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,8 +1184,8 @@ void common_hal_socketpool_socket_settimeout(socketpool_socket_obj_t *self, uint
11841184
}
11851185

11861186
int common_hal_socketpool_socket_setsockopt(socketpool_socket_obj_t *self, int level, int optname, const void *value, size_t optlen) {
1187-
int one = 1;
1188-
bool enable = optlen == sizeof(&one) && memcmp(value, &one, optlen);
1187+
int zero = 0;
1188+
bool enable = optlen == sizeof(&zero) && memcmp(value, &zero, optlen);
11891189

11901190
switch (level) {
11911191
case SOCKETPOOL_IPPROTO_TCP:

0 commit comments

Comments
 (0)