提交 63afe5cc authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Avoid "warning: missing initializer for member” [-Wmissing-field-initializers]

Based on rationale given in https://stackoverflow.com/questions/21658485/why-do-i-get-warning-missing-initializer-for-member-wmissing-field-initial.

Using {} for initializing a struct is not good enough since we are not given any value to it, and hence the gcc warning. Doing {0} just sets the value of the first field in the struct, so it's not good either.
上级 f5d48748
...@@ -54,9 +54,7 @@ namespace RTC ...@@ -54,9 +54,7 @@ namespace RTC
RTC::UdpSocket* udpSocket{ nullptr }; RTC::UdpSocket* udpSocket{ nullptr };
RTC::TransportTuple* tuple{ nullptr }; RTC::TransportTuple* tuple{ nullptr };
// Others. // Others.
struct sockaddr_storage remoteAddrStorage struct sockaddr_storage remoteAddrStorage;
{
};
}; };
} // namespace RTC } // namespace RTC
......
...@@ -144,9 +144,7 @@ namespace RTC ...@@ -144,9 +144,7 @@ namespace RTC
struct HeaderExtensionIds headerExtensionIds; struct HeaderExtensionIds headerExtensionIds;
// Others (Mirroring). // Others (Mirroring).
MirroringOptions mirroringOptions{}; MirroringOptions mirroringOptions{};
struct sockaddr_storage mirrorAddrStorage struct sockaddr_storage mirrorAddrStorage;
{
};
// Others (REMB) // Others (REMB)
std::tuple<uint64_t, std::vector<uint32_t>> recvRemb; std::tuple<uint64_t, std::vector<uint32_t>> recvRemb;
}; };
......
...@@ -98,9 +98,7 @@ protected: ...@@ -98,9 +98,7 @@ protected:
size_t bufferDataLen{ 0 }; size_t bufferDataLen{ 0 };
std::string localIP; std::string localIP;
uint16_t localPort{ 0 }; uint16_t localPort{ 0 };
struct sockaddr_storage peerAddr struct sockaddr_storage peerAddr;
{
};
std::string peerIP; std::string peerIP;
uint16_t peerPort{ 0 }; uint16_t peerPort{ 0 };
}; };
......
...@@ -56,9 +56,7 @@ private: ...@@ -56,9 +56,7 @@ private:
bool isClosing{ false }; bool isClosing{ false };
protected: protected:
struct sockaddr_storage localAddr struct sockaddr_storage localAddr;
{
};
std::string localIP; std::string localIP;
uint16_t localPort{ 0 }; uint16_t localPort{ 0 };
}; };
......
...@@ -66,9 +66,7 @@ private: ...@@ -66,9 +66,7 @@ private:
size_t sentBytes{ 0 }; size_t sentBytes{ 0 };
protected: protected:
struct sockaddr_storage localAddr struct sockaddr_storage localAddr;
{
};
std::string localIP; std::string localIP;
uint16_t localPort{ 0 }; uint16_t localPort{ 0 };
}; };
......
...@@ -922,9 +922,7 @@ namespace RTC ...@@ -922,9 +922,7 @@ namespace RTC
MS_TRACE(); MS_TRACE();
int64_t ret; int64_t ret;
// clang-format off struct timeval dtlsTimeout;
struct timeval dtlsTimeout{};
// clang-format on
uint64_t timeoutMs; uint64_t timeoutMs;
// NOTE: If ret == 0 then ignore the value in dtlsTimeout. // NOTE: If ret == 0 then ignore the value in dtlsTimeout.
......
...@@ -55,7 +55,7 @@ namespace RTC ...@@ -55,7 +55,7 @@ namespace RTC
MS_TRACE(); MS_TRACE();
srtp_err_status_t err; srtp_err_status_t err;
srtp_policy_t policy{}; srtp_policy_t policy;
// Set all policy fields to 0. // Set all policy fields to 0.
std::memset(&policy, 0, sizeof(srtp_policy_t)); std::memset(&policy, 0, sizeof(srtp_policy_t));
......
...@@ -85,9 +85,7 @@ namespace RTC ...@@ -85,9 +85,7 @@ namespace RTC
int err; int err;
uv_tcp_t* uvHandle{ nullptr }; uv_tcp_t* uvHandle{ nullptr };
struct sockaddr_storage bindAddr struct sockaddr_storage bindAddr;
{
};
const char* listenIp; const char* listenIp;
uint16_t initialPort; uint16_t initialPort;
uint16_t iteratingPort; uint16_t iteratingPort;
......
...@@ -84,9 +84,7 @@ namespace RTC ...@@ -84,9 +84,7 @@ namespace RTC
int err; int err;
uv_udp_t* uvHandle{ nullptr }; uv_udp_t* uvHandle{ nullptr };
// clang-format off struct sockaddr_storage bindAddr;
struct sockaddr_storage bindAddr{};
// clang-format on
const char* listenIp; const char* listenIp;
uint16_t initialPort; uint16_t initialPort;
uint16_t iteratingPort; uint16_t iteratingPort;
......
...@@ -596,9 +596,7 @@ bool isBindableIp(const std::string& ip, int family, int* bindErrno) ...@@ -596,9 +596,7 @@ bool isBindableIp(const std::string& ip, int family, int* bindErrno)
{ {
MS_TRACE(); MS_TRACE();
// clang-format off struct sockaddr_storage bindAddr;
struct sockaddr_storage bindAddr{};
// clang-format on
int bindSocket; int bindSocket;
int err{ 0 }; int err{ 0 };
bool success; bool success;
......
...@@ -12,8 +12,8 @@ namespace Utils ...@@ -12,8 +12,8 @@ namespace Utils
uint32_t Crypto::seed; uint32_t Crypto::seed;
HMAC_CTX Crypto::hmacSha1Ctx; HMAC_CTX Crypto::hmacSha1Ctx;
uint8_t Crypto::hmacSha1Buffer[20]; // SHA-1 result is 20 bytes long. uint8_t Crypto::hmacSha1Buffer[20]; // SHA-1 result is 20 bytes long.
const uint32_t Crypto::crc32Table[] =
// clang-format off // clang-format off
const uint32_t Crypto::crc32Table[] =
{ {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
......
...@@ -14,9 +14,7 @@ namespace Utils ...@@ -14,9 +14,7 @@ namespace Utils
{ {
MS_TRACE(); MS_TRACE();
// clang-format off struct stat fileStat;
struct stat fileStat{};
// clang-format on
int err; int err;
// Ensure the given file exists. // Ensure the given file exists.
......
...@@ -169,7 +169,7 @@ void TcpConnection::Write(const uint8_t* data, size_t len) ...@@ -169,7 +169,7 @@ void TcpConnection::Write(const uint8_t* data, size_t len)
if (len == 0) if (len == 0)
return; return;
uv_buf_t buffer{}; uv_buf_t buffer;
int written; int written;
int err; int err;
......
...@@ -45,9 +45,7 @@ TcpServer::TcpServer(const std::string& ip, uint16_t port, int backlog) ...@@ -45,9 +45,7 @@ TcpServer::TcpServer(const std::string& ip, uint16_t port, int backlog)
MS_THROW_ERROR("uv_tcp_init() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_tcp_init() failed: %s", uv_strerror(err));
} }
// clang-format off struct sockaddr_storage bindAddr;
struct sockaddr_storage bindAddr{};
// clang-format on
switch (Utils::IP::GetFamily(ip)) switch (Utils::IP::GetFamily(ip))
{ {
......
...@@ -69,9 +69,7 @@ UdpSocket::UdpSocket(const std::string& ip, uint16_t port) ...@@ -69,9 +69,7 @@ UdpSocket::UdpSocket(const std::string& ip, uint16_t port)
MS_THROW_ERROR("uv_udp_init() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_udp_init() failed: %s", uv_strerror(err));
} }
// clang-format off struct sockaddr_storage bindAddr;
struct sockaddr_storage bindAddr{};
// clang-format on
switch (Utils::IP::GetFamily(ip)) switch (Utils::IP::GetFamily(ip))
{ {
...@@ -191,7 +189,7 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add ...@@ -191,7 +189,7 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add
if (len == 0) if (len == 0)
return; return;
uv_buf_t buffer{}; uv_buf_t buffer;
int sent; int sent;
int err; int err;
...@@ -268,9 +266,7 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const std::string& ip, uin ...@@ -268,9 +266,7 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const std::string& ip, uin
if (len == 0) if (len == 0)
return; return;
// clang-format off struct sockaddr_storage addr;
struct sockaddr_storage addr{};
// clang-format on
switch (Utils::IP::GetFamily(ip)) switch (Utils::IP::GetFamily(ip))
{ {
......
...@@ -146,7 +146,7 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len) ...@@ -146,7 +146,7 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len)
if (len == 0) if (len == 0)
return; return;
uv_buf_t buffer{}; uv_buf_t buffer;
int written; int written;
int err; int err;
......
...@@ -125,8 +125,8 @@ void ignoreSignals() ...@@ -125,8 +125,8 @@ void ignoreSignals()
MS_TRACE(); MS_TRACE();
int err; int err;
struct sigaction act;
// clang-format off // clang-format off
struct sigaction act{};
std::map<std::string, int> ignoredSignals = std::map<std::string, int> ignoredSignals =
{ {
{ "PIPE", SIGPIPE }, { "PIPE", SIGPIPE },
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论