From 0563f74f129ed4cd0a618ca5fcb380c8a3a67191 Mon Sep 17 00:00:00 2001 From: ryo Date: Fri, 14 Oct 2022 19:39:32 +0000 Subject: [PATCH] Avoid error of "-Wreturn-local-addr", and simplify the logic. However, -Wreturn-local-addr is still disabled by default by GCC_NO_RETURN_LOCAL_ADDR in bsd.own.mk because it causes errors in other parts. --- sys/netinet/in_pcb.c | 17 +++++++---------- sys/netinet6/in6_pcb.c | 17 +++++++---------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index fb41acc6b698..20e140630a1b 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $NetBSD: in_pcb.c,v 1.190 2022/08/29 09:14:02 knakahara Exp $ */ +/* $NetBSD: in_pcb.c,v 1.191 2022/10/14 19:39:32 ryo Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -93,7 +93,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.190 2022/08/29 09:14:02 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.191 2022/10/14 19:39:32 ryo Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -935,6 +935,7 @@ in_pcblookup_port(struct inpcbtable *table, struct in_addr laddr, if (vp && table->vestige) { void *state = (*table->vestige->init_ports4)(laddr, lport_arg, lookup_wildcard); vestigial_inpcb_t better; + bool has_better = false; while (table->vestige && (*table->vestige->next_port4)(state, vp)) { @@ -959,7 +960,7 @@ in_pcblookup_port(struct inpcbtable *table, struct in_addr laddr, continue; if (wildcard < matchwild) { better = *vp; - match = (void*)&better; + has_better = true; matchwild = wildcard; if (matchwild == 0) @@ -967,13 +968,9 @@ in_pcblookup_port(struct inpcbtable *table, struct in_addr laddr, } } - if (match) { - if (match != (void*)&better) - return match; - else { - *vp = better; - return 0; - } + if (has_better) { + *vp = better; + return 0; } } diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 41fd29eb56a2..53fbd5903d5e 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -1,4 +1,4 @@ -/* $NetBSD: in6_pcb.c,v 1.170 2022/08/29 09:14:02 knakahara Exp $ */ +/* $NetBSD: in6_pcb.c,v 1.171 2022/10/14 19:39:32 ryo Exp $ */ /* $KAME: in6_pcb.c,v 1.84 2001/02/08 18:02:08 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.170 2022/08/29 09:14:02 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.171 2022/10/14 19:39:32 ryo Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1055,6 +1055,7 @@ in6_pcblookup_port(struct inpcbtable *table, struct in6_addr *laddr6, if (vp && table->vestige && table->vestige->init_ports6) { struct vestigial_inpcb better; + bool has_better = false; void *state; state = (*table->vestige->init_ports6)(laddr6, @@ -1087,7 +1088,7 @@ in6_pcblookup_port(struct inpcbtable *table, struct in6_addr *laddr6, continue; if (wildcard < matchwild) { better = *vp; - match = (void*)&better; + has_better = true; matchwild = wildcard; if (matchwild == 0) @@ -1095,13 +1096,9 @@ in6_pcblookup_port(struct inpcbtable *table, struct in6_addr *laddr6, } } - if (match) { - if (match != (void*)&better) - return match; - else { - *vp = better; - return 0; - } + if (has_better) { + *vp = better; + return 0; } } return (match);