Skip to content
Permalink
Browse files

Specify minimum buffer sizes

  • Loading branch information
arr2036 committed Sep 24, 2019
1 parent 8481e23 commit 91242813dea001f00e12a4b334d0e58d75e0d889
Showing with 10 additions and 10 deletions.
  1. +10 −10 src/lib/util/net.h
@@ -163,37 +163,37 @@ uint16_t fr_udp_checksum(uint8_t const *data, uint16_t len, uint16_t checksum,
int fr_udp_header_check(uint8_t const *data, uint16_t remaining, ip_header_t const *ip);
uint16_t fr_ip_header_checksum(uint8_t const *data, uint8_t ihl);

static inline void fr_put_be16(uint8_t *a, uint16_t val)
static inline void fr_put_be16(uint8_t a[static sizeof(uint16_t)], uint16_t val)
{
a[0] = (val >> 8) & 0xff;
a[1] = val & 0xff;
}

static inline void fr_put_be32(uint8_t *a, uint32_t val)
static inline void fr_put_be32(uint8_t a[static sizeof(uint32_t)], uint32_t val)
{
fr_put_be16(a, (uint16_t) ((val >> 16) & 0xffff));
fr_put_be16(a + 2, (uint16_t) (val & 0xffff));
fr_put_be16(a + sizeof(uint16_t), (uint16_t) (val & 0xffff));
}

static inline void fr_put_be64(uint8_t *a, uint64_t val)
static inline void fr_put_be64(uint8_t a[static sizeof(uint64_t)], uint64_t val)
{
fr_put_be32(a, (uint32_t) ((val >> 32) & 0xffffffff));
fr_put_be32(a + 4, (uint32_t) (val & 0xffffffff));
fr_put_be32(a + sizeof(uint32_t), (uint32_t) (val & 0xffffffff));
}

static inline uint16_t fr_get_be16(uint8_t const *a)
static inline uint16_t fr_get_be16(uint8_t const a[static sizeof(uint16_t)])
{
return (a[0] << 8) | a[1];
}

static inline uint32_t fr_get_be32(uint8_t const *a)
static inline uint32_t fr_get_be32(uint8_t const a[static sizeof(uint32_t)])
{
return ((uint32_t) fr_get_be16(a) << 16) | fr_get_be16(a + 2);
return ((uint32_t) fr_get_be16(a) << 16) | fr_get_be16(a + sizeof(uint16_t));
}

static inline uint64_t fr_get_be64(uint8_t const *a)
static inline uint64_t fr_get_be64(uint8_t const a[static sizeof(uint64_t)])
{
return ((uint64_t) fr_get_be32(a) << 32) | fr_get_be32(a + 4);
return ((uint64_t) fr_get_be32(a) << 32) | fr_get_be32(a + sizeof(uint32_t));
}
#ifdef __cplusplus
}

0 comments on commit 9124281

Please sign in to comment.
You can’t perform that action at this time.