summaryrefslogtreecommitdiff
path: root/toxcore/network.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-02-24 11:50:13 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-02-24 11:53:43 +0000
commit4c8ee2a20f6525d74a6b9474310f397d355e2b10 (patch)
treec8e9c7c1dd22237ebaca58cccf05afebcad4e429 /toxcore/network.c
parentb2a2a0bbc7c3aac655bc9efc1c8f385adfe90a3f (diff)
Minor cleanups: dead stores and avoiding complex macros.
Diffstat (limited to 'toxcore/network.c')
-rw-r--r--toxcore/network.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/toxcore/network.c b/toxcore/network.c
index 8a951dbb..99768829 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -1484,16 +1484,18 @@ size_t net_pack_u16(uint8_t *bytes, uint16_t v)
1484 1484
1485size_t net_pack_u32(uint8_t *bytes, uint32_t v) 1485size_t net_pack_u32(uint8_t *bytes, uint32_t v)
1486{ 1486{
1487 bytes += net_pack_u16(bytes, (v >> 16) & 0xffff); 1487 uint8_t *p = bytes;
1488 bytes += net_pack_u16(bytes, v & 0xffff); 1488 p += net_pack_u16(p, (v >> 16) & 0xffff);
1489 return sizeof(v); 1489 p += net_pack_u16(p, v & 0xffff);
1490 return p - bytes;
1490} 1491}
1491 1492
1492size_t net_pack_u64(uint8_t *bytes, uint64_t v) 1493size_t net_pack_u64(uint8_t *bytes, uint64_t v)
1493{ 1494{
1494 bytes += net_pack_u32(bytes, (v >> 32) & 0xffffffff); 1495 uint8_t *p = bytes;
1495 bytes += net_pack_u32(bytes, v & 0xffffffff); 1496 p += net_pack_u32(p, (v >> 32) & 0xffffffff);
1496 return sizeof(v); 1497 p += net_pack_u32(p, v & 0xffffffff);
1498 return p - bytes;
1497} 1499}
1498 1500
1499size_t net_unpack_u16(const uint8_t *bytes, uint16_t *v) 1501size_t net_unpack_u16(const uint8_t *bytes, uint16_t *v)
@@ -1506,18 +1508,20 @@ size_t net_unpack_u16(const uint8_t *bytes, uint16_t *v)
1506 1508
1507size_t net_unpack_u32(const uint8_t *bytes, uint32_t *v) 1509size_t net_unpack_u32(const uint8_t *bytes, uint32_t *v)
1508{ 1510{
1511 const uint8_t *p = bytes;
1509 uint16_t lo, hi; 1512 uint16_t lo, hi;
1510 bytes += net_unpack_u16(bytes, &hi); 1513 p += net_unpack_u16(p, &hi);
1511 bytes += net_unpack_u16(bytes, &lo); 1514 p += net_unpack_u16(p, &lo);
1512 *v = ((uint32_t)hi << 16) | lo; 1515 *v = ((uint32_t)hi << 16) | lo;
1513 return sizeof(*v); 1516 return p - bytes;
1514} 1517}
1515 1518
1516size_t net_unpack_u64(const uint8_t *bytes, uint64_t *v) 1519size_t net_unpack_u64(const uint8_t *bytes, uint64_t *v)
1517{ 1520{
1521 const uint8_t *p = bytes;
1518 uint32_t lo, hi; 1522 uint32_t lo, hi;
1519 bytes += net_unpack_u32(bytes, &hi); 1523 p += net_unpack_u32(p, &hi);
1520 bytes += net_unpack_u32(bytes, &lo); 1524 p += net_unpack_u32(p, &lo);
1521 *v = ((uint64_t)hi << 32) | lo; 1525 *v = ((uint64_t)hi << 32) | lo;
1522 return sizeof(*v); 1526 return p - bytes;
1523} 1527}