diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2023-09-21 14:49:38 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2023-09-27 17:25:51 +0200 |
commit | 5b6c68c2e4995b94110b62e9e8346fb372451e31 (patch) | |
tree | 5c10ec7a0a154598f24cd13bbc329805966e462b /util.c | |
parent | 9178a9e3462d7fb931e4316d99eccbb3e7460cb7 (diff) | |
download | passt-5b6c68c2e4995b94110b62e9e8346fb372451e31.tar passt-5b6c68c2e4995b94110b62e9e8346fb372451e31.tar.gz passt-5b6c68c2e4995b94110b62e9e8346fb372451e31.tar.bz2 passt-5b6c68c2e4995b94110b62e9e8346fb372451e31.tar.lz passt-5b6c68c2e4995b94110b62e9e8346fb372451e31.tar.xz passt-5b6c68c2e4995b94110b62e9e8346fb372451e31.tar.zst passt-5b6c68c2e4995b94110b62e9e8346fb372451e31.zip |
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 <string.h> 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 <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -38,15 +38,15 @@ /** * ipv6_l4hdr() - Find pointer to L4 header in IPv6 packet and extract protocol - * @p: Packet pool, packet number @index has IPv6 header at @offset - * @index: Index of packet in pool + * @p: Packet pool, packet number @idx has IPv6 header at @offset + * @idx: Index of packet in pool * @offset: Pre-calculated IPv6 header offset * @proto: Filled with L4 protocol number * @dlen: Data length (payload excluding header extensions), set on return * * Return: pointer to L4 header, NULL if not found */ -char *ipv6_l4hdr(const struct pool *p, int index, size_t offset, uint8_t *proto, +char *ipv6_l4hdr(const struct pool *p, int idx, size_t offset, uint8_t *proto, size_t *dlen) { struct ipv6_opt_hdr *o; @@ -55,8 +55,8 @@ char *ipv6_l4hdr(const struct pool *p, int index, size_t offset, uint8_t *proto, int hdrlen; uint8_t nh; - base = packet_get(p, index, 0, 0, NULL); - ip6h = packet_get(p, index, offset, sizeof(*ip6h), dlen); + base = packet_get(p, idx, 0, 0, NULL); + ip6h = packet_get(p, idx, offset, sizeof(*ip6h), dlen); if (!ip6h) return NULL; @@ -66,7 +66,7 @@ char *ipv6_l4hdr(const struct pool *p, int index, size_t offset, uint8_t *proto, if (!IPV6_NH_OPT(nh)) goto found; - while ((o = packet_get_try(p, index, offset, sizeof(*o), dlen))) { + while ((o = packet_get_try(p, idx, offset, sizeof(*o), dlen))) { nh = o->nexthdr; hdrlen = (o->hdrlen + 1) * 8; |