From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id A891C5A026D for ; Mon, 18 Sep 2023 10:16:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695024969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CZICyhVmupUo7PTqCfviu8Cn+O0fob33M4CHL5+x/KE=; b=GktqjSOTTNtg8A5VLVuMn4NcnnChUR1Qbm16nQvHp86CpkQK+BKXDV3ze08wWDGHCu1Ykq rptEGWHMhVzvW5KeP1mDro9hNK/P9tgUZUeO6JKNkQXwsDyOPBV/JObPHjKkw47j5AfiGn 9NVEmasYilxLstKM+CgbZlIXAR8LUtk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-fzGz2L40O8SqvA8sgL-QCA-1; Mon, 18 Sep 2023 04:16:03 -0400 X-MC-Unique: fzGz2L40O8SqvA8sgL-QCA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 36F203C025B1; Mon, 18 Sep 2023 08:16:03 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.36]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 885BC20268CB; Mon, 18 Sep 2023 08:16:02 +0000 (UTC) Date: Mon, 18 Sep 2023 10:16:00 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 1/2] packet: Avoid shadowing index(3) Message-ID: <20230918101524.3cc2fee7@elisabeth> In-Reply-To: <20230915064337.2380211-2-david@gibson.dropbear.id.au> References: <20230915064337.2380211-1-david@gibson.dropbear.id.au> <20230915064337.2380211-2-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: SRUCYFFUI62TXIWDG67OLLDB5LP3Y4NS X-Message-ID-Hash: SRUCYFFUI62TXIWDG67OLLDB5LP3Y4NS X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Fri, 15 Sep 2023 16:43:36 +1000 David Gibson wrote: > 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 few > places in packet.[ch] which hit this trap so rename the variables to avoid > it. > > Signed-off-by: David Gibson > --- > packet.c | 28 ++++++++++++++-------------- > packet.h | 10 +++++----- > 2 files changed, 19 insertions(+), 19 deletions(-) > > diff --git a/packet.c b/packet.c > index ce807e2..8e3a87c 100644 > --- a/packet.c > +++ b/packet.c > @@ -33,11 +33,11 @@ > void packet_add_do(struct pool *p, size_t len, const char *start, > const char *func, int line) > { > - size_t index = p->count; > + size_t idx = p->count; > > - if (index >= p->size) { > + if (idx >= p->size) { > trace("add packet index %lu to pool with size %lu, %s:%i", > - index, p->size, func, line); > + idx, p->size, func, line); > return; > } > > @@ -66,8 +66,8 @@ void packet_add_do(struct pool *p, size_t len, const char *start, > } > #endif > > - p->pkt[index].offset = start - p->buf; > - p->pkt[index].len = len; > + p->pkt[idx].offset = start - p->buf; > + p->pkt[idx].len = len; > > p->count++; > } > @@ -84,13 +84,13 @@ void packet_add_do(struct pool *p, size_t len, const char *start, > * > * Return: pointer to start of data range, NULL on invalid range or descriptor > */ > -void *packet_get_do(const struct pool *p, size_t index, size_t offset, > +void *packet_get_do(const struct pool *p, size_t idx, size_t offset, Really minor, but... the comment about @index should be updated as well. -- Stefano