Commit d571ed87 authored by Louis Royer's avatar Louis Royer

Fix warning from IPv6FromString

```
In function 'bool IPv6FromString(const char*, uint8_t*)',
    inlined from 'OctetString utils::IpToOctetString(const string&)' at /UERANSIM/src/utils/common.cpp:200:28:
/UERANSIM/src/utils/common.cpp:49:11: warning: 'void* memset(void*, int, size_t)' forming offset [1, 15] is out of the bounds [0, 1] [-Warray-bounds]
   49 |     memset(address, 0, 16);
      |     ~~~~~~^~~~~~~~~~~~~~~~
```
parent a0829b48
......@@ -30,7 +30,7 @@ static_assert(sizeof(long long) == sizeof(uint64_t));
static std::atomic<int> g_idCounter = 1;
static bool IPv6FromString(const char *szAddress, uint8_t *address)
static bool IPv6FromString(const char *szAddress, std::vector<uint8_t>& address)
{
auto asciiToHex = [](char c) {
c |= 0x20;
......@@ -46,7 +46,9 @@ static bool IPv6FromString(const char *szAddress, uint8_t *address)
uint8_t colons = 0;
uint8_t pos = 0;
memset(address, 0, 16);
address.clear();
std::vector<uint8_t> emptyAddress{16};
address.insert(address.begin(), emptyAddress.begin(), emptyAddress.end());
for (uint8_t i = 1; i <= 39; i++)
{
......@@ -60,12 +62,12 @@ static bool IPv6FromString(const char *szAddress, uint8_t *address)
else if (szAddress[i] == '\0')
break;
}
for (uint8_t i = 0; i <= 39 && pos < 16; i++)
for (uint8_t i = 0; i <= 39 && pos < address.size(); i++)
{
if (szAddress[i] == ':' || szAddress[i] == '\0')
{
address[pos] = acc >> 8;
address[pos + 1] = acc;
address.at(pos) = acc >> 8;
address.at(pos + 1) = acc;
acc = 0;
if (colons && i && szAddress[i - 1] == ':')
......@@ -197,7 +199,7 @@ OctetString utils::IpToOctetString(const std::string &address)
else if (ipVersion == 6)
{
std::vector<uint8_t> data{16};
if (!IPv6FromString(address.c_str(), data.data()))
if (!IPv6FromString(address.c_str(), data))
return {};
return OctetString(std::move(data));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment