From 5b6c68c2e4995b94110b62e9e8346fb372451e31 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 21 Sep 2023 14:49:38 +1000 Subject: Avoid shadowing index(3) A classic gotcha of the standard C library is that its unwise to call any variable 'index' because it will shadow the standard string library function index(3). This can cause warnings from cppcheck amongst others, and it also means that if the variable is removed you tend to get confusing type errors (or sometimes nothing at all) instead of a nice simple "name is not defined" error. Strictly speaking this only occurs if is included, but that is so common that as a rule it's best to just avoid it always. We have a number of places which hit this trap, so rename variables and parameters to avoid it. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- tcp.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tcp.c') diff --git a/tcp.c b/tcp.c index 43a1fc0..049e3d8 100644 --- a/tcp.c +++ b/tcp.c @@ -563,20 +563,20 @@ static unsigned int tcp6_l2_flags_buf_used; /* TCP connections */ union tcp_conn tc[TCP_MAX_CONNS]; -#define CONN(index) (&tc[(index)].tap) +#define CONN(idx) (&tc[(idx)].tap) #define CONN_IDX(conn) ((union tcp_conn *)(conn) - tc) /** conn_at_idx() - Find a connection by index, if present - * @index: Index of connection to lookup + * @idx: Index of connection to lookup * - * Return: pointer to connection, or NULL if @index is out of bounds + * Return: pointer to connection, or NULL if @idx is out of bounds */ -static inline struct tcp_tap_conn *conn_at_idx(int index) +static inline struct tcp_tap_conn *conn_at_idx(int idx) { - if ((index < 0) || (index >= TCP_MAX_CONNS)) + if ((idx < 0) || (idx >= TCP_MAX_CONNS)) return NULL; - ASSERT(!(CONN(index)->c.spliced)); - return CONN(index); + ASSERT(!(CONN(idx)->c.spliced)); + return CONN(idx); } /* Table for lookup from remote address, local port, remote port */ -- cgit v1.2.3