Skip to content

Commit 95b3520

Browse files
committed
unix/modsocket: Fix usage of pointers to locals outside scope
1 parent 2465222 commit 95b3520

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

unix/modsocket.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ STATIC mp_obj_t socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
266266

267267
const void *optval;
268268
socklen_t optlen;
269+
int val;
269270
if (MP_OBJ_IS_INT(args[3])) {
270-
int val = mp_obj_int_get_truncated(args[3]);
271+
val = mp_obj_int_get_truncated(args[3]);
271272
optval = &val;
272273
optlen = sizeof(val);
273274
} else {
@@ -428,12 +429,12 @@ STATIC mp_obj_t mod_socket_getaddrinfo(mp_uint_t n_args, const mp_obj_t *args) {
428429
const char *host = mp_obj_str_get_str(args[0]);
429430
const char *serv = NULL;
430431
struct addrinfo hints;
432+
char buf[6];
431433
memset(&hints, 0, sizeof(hints));
432434
// getaddrinfo accepts port in string notation, so however
433435
// it may seem stupid, we need to convert int to str
434436
if (MP_OBJ_IS_SMALL_INT(args[1])) {
435437
unsigned port = (unsigned short)MP_OBJ_SMALL_INT_VALUE(args[1]);
436-
char buf[6];
437438
sprintf(buf, "%u", port);
438439
serv = buf;
439440
hints.ai_flags = AI_NUMERICSERV;

0 commit comments

Comments
 (0)