Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled warnings various platforms and fixed C++20 Windows build #2411

Merged
merged 11 commits into from
Feb 9, 2023
12 changes: 7 additions & 5 deletions haicrypt/cryspr-mbedtls.c
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ written by
GnuTLS/Nettle CRYSPR/4SRT (CRYypto Service PRovider for SRT)
*****************************************************************************/

#include "platform_sys.h"

#include "hcrypt.h"

#include <string.h>
@@ -75,9 +77,9 @@ int crysprMbedtls_AES_SetKey(
// kstr_len is in "bytes" convention (16, 24, 32).

if (bEncrypt) { /* Encrypt key */
ret = mbedtls_aes_setkey_enc(aes_key, kstr, kstr_len*8);
ret = mbedtls_aes_setkey_enc(aes_key, kstr, (unsigned int)kstr_len*8);
} else { /* Decrypt key */
ret = mbedtls_aes_setkey_dec(aes_key, kstr, kstr_len*8);
ret = mbedtls_aes_setkey_dec(aes_key, kstr, (unsigned int)kstr_len*8);
}

return ret == 0 ? 0 : -1;
@@ -91,8 +93,8 @@ int crysprMbedtls_AES_EcbCipher( /* AES Electronic Codebook cipher*/
unsigned char *out_txt, /* dst (cipher text) */
size_t *outlen) /* dst len */
{
int nblk = inlen/CRYSPR_AESBLKSZ;
int nmore = inlen%CRYSPR_AESBLKSZ;
int nblk = (int)(inlen/CRYSPR_AESBLKSZ);
int nmore = (int)(inlen%CRYSPR_AESBLKSZ);
int i;

if (bEncrypt) {
@@ -216,7 +218,7 @@ int crysprMbedtls_KmPbkdf2(

ret = mbedtls_pkcs5_pbkdf2_hmac(&mdctx,
(unsigned char*)passwd, passwd_len, salt, salt_len,
itr, key_len, out);
itr, (uint32_t)key_len, out);

mbedtls_md_free(&mdctx);

2 changes: 2 additions & 0 deletions haicrypt/cryspr.c
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ written by
CRYSPR/4SRT Initial implementation.
*****************************************************************************/

#include "platform_sys.h"

#include "hcrypt.h"
#include "cryspr.h"

4 changes: 0 additions & 4 deletions haicrypt/hcrypt.h
Original file line number Diff line number Diff line change
@@ -32,10 +32,6 @@ written by
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#if defined(_MSC_VER)
#pragma warning(disable:4267)
#pragma warning(disable:4018)
#endif
#else
#include <sys/time.h>
#endif
4 changes: 3 additions & 1 deletion haicrypt/hcrypt_ctx_rx.c
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ written by
Adaptation for SRT.
*****************************************************************************/

#include "platform_sys.h"

#include <string.h> /* memcpy */
#include "hcrypt.h"

@@ -190,7 +192,7 @@ int hcryptCtx_Rx_ParseKM(hcrypt_Session *crypto, unsigned char *km_msg, size_t m
/* Unwrap SEK(s) and set in context */
if (0 > crypto->cryspr->km_unwrap(crypto->cryspr_cb, seks,
&km_msg[HCRYPT_MSG_KM_OFS_SALT + salt_len],
(sek_cnt * sek_len) + HAICRYPT_WRAPKEY_SIGN_SZ)) {
(unsigned int)((sek_cnt * sek_len) + HAICRYPT_WRAPKEY_SIGN_SZ))) {
HCRYPT_LOG(LOG_WARNING, "%s", "unwrap key failed\n");
return(-2); //Report unmatched shared secret
}
10 changes: 6 additions & 4 deletions haicrypt/hcrypt_ctx_tx.c
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ written by
Adaptation for SRT.
*****************************************************************************/

#include "platform_sys.h"

#include <string.h> /* memcpy */
#ifdef _WIN32
#include <winsock2.h>
@@ -52,14 +54,14 @@ int hcryptCtx_Tx_Rekey(hcrypt_Session *crypto, hcrypt_Ctx *ctx)

/* Generate Salt */
ctx->salt_len = HAICRYPT_SALT_SZ;
if (0 > (iret = crypto->cryspr->prng(ctx->salt, ctx->salt_len))) {
if (0 > (iret = crypto->cryspr->prng(ctx->salt, (int)ctx->salt_len))) {
HCRYPT_LOG(LOG_ERR, "PRNG(salt[%zd]) failed\n", ctx->salt_len);
return(iret);
}

/* Generate SEK */
ctx->sek_len = ctx->cfg.key_len;
if (0 > (iret = crypto->cryspr->prng(ctx->sek, ctx->sek_len))) {
if (0 > (iret = crypto->cryspr->prng(ctx->sek, (int)ctx->sek_len))) {
HCRYPT_LOG(LOG_ERR, "PRNG(sek[%zd] failed\n", ctx->sek_len);
return(iret);
}
@@ -195,7 +197,7 @@ int hcryptCtx_Tx_Refresh(hcrypt_Session *crypto)

HCRYPT_LOG(LOG_DEBUG, "refresh/generate SEK. salt_len=%d sek_len=%d\n", (int)new_ctx->salt_len, (int)new_ctx->sek_len);

if (0 > crypto->cryspr->prng(new_ctx->sek, new_ctx->sek_len)) {
if (0 > crypto->cryspr->prng(new_ctx->sek, (int)new_ctx->sek_len)) {
HCRYPT_LOG(LOG_ERR, "PRNG(sek[%zd] failed\n", new_ctx->sek_len);
return(-1);
}
@@ -322,7 +324,7 @@ int hcryptCtx_Tx_AsmKM(hcrypt_Session *crypto, hcrypt_Ctx *ctx, unsigned char *a
}
if (0 > crypto->cryspr->km_wrap(crypto->cryspr_cb,
&km_msg[HCRYPT_MSG_KM_OFS_SALT + ctx->salt_len],
seks, sek_cnt * ctx->sek_len)) {
seks, (unsigned int)(sek_cnt * ctx->sek_len))) {

HCRYPT_LOG(LOG_ERR, "%s", "wrap key failed\n");
return(-1);
4 changes: 2 additions & 2 deletions haicrypt/hcrypt_msg.h
Original file line number Diff line number Diff line change
@@ -150,8 +150,8 @@ typedef struct {
#define hcryptMsg_KM_GetSaltLen(msg) (size_t)((msg)[HCRYPT_MSG_KM_OFS_SLEN] * 4)
#define hcryptMsg_KM_GetSekLen(msg) (size_t)((msg)[HCRYPT_MSG_KM_OFS_KLEN] * 4)

#define hcryptMsg_KM_SetSaltLen(msg,len)do {(msg)[HCRYPT_MSG_KM_OFS_SLEN] = (len)/4;} while(0)
#define hcryptMsg_KM_SetSekLen(msg,len) do {(msg)[HCRYPT_MSG_KM_OFS_KLEN] = (len)/4;} while(0)
#define hcryptMsg_KM_SetSaltLen(msg,len)do {(msg)[HCRYPT_MSG_KM_OFS_SLEN] = (unsigned char)(len)/4;} while(0)
#define hcryptMsg_KM_SetSekLen(msg,len) do {(msg)[HCRYPT_MSG_KM_OFS_KLEN] = (unsigned char)(len)/4;} while(0)


#endif /* HCRYPT_MSG_H */
4 changes: 3 additions & 1 deletion haicrypt/hcrypt_rx.c
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ written by
Adaptation for SRT.
*****************************************************************************/

#include "platform_sys.h"

#include <stdlib.h> /* NULL */
#include <string.h> /* memcmp */
#include "hcrypt.h"
@@ -53,7 +55,7 @@ int HaiCrypt_Rx_Data(HaiCrypt_Handle hhc,
if (0 > (nb = crypto->cryspr->ms_decrypt(crypto->cryspr_cb, ctx, &indata, 1, NULL, NULL, NULL))) {
HCRYPT_LOG(LOG_ERR, "%s", "ms_decrypt failed\n");
} else {
nb = indata.len;
nb = (int)indata.len;
}
} else { /* No key received yet */
nb = 0;
4 changes: 2 additions & 2 deletions srtcore/buffer_rcv.h
Original file line number Diff line number Diff line change
@@ -226,8 +226,8 @@ class CRcvBuffer
inline int cmpPos(int pos2, int pos1) const
{
// XXX maybe not the best implementation, but this keeps up to the rule
const int off1 = pos1 >= m_iStartPos ? pos1 - m_iStartPos : pos1 + m_szSize - m_iStartPos;
const int off2 = pos2 >= m_iStartPos ? pos2 - m_iStartPos : pos2 + m_szSize - m_iStartPos;
const int off1 = pos1 >= m_iStartPos ? pos1 - m_iStartPos : pos1 + (int)m_szSize - m_iStartPos;
const int off2 = pos2 >= m_iStartPos ? pos2 - m_iStartPos : pos2 + (int)m_szSize - m_iStartPos;

return off2 - off1;
}
2 changes: 1 addition & 1 deletion srtcore/cache.cpp
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ srt::CInfoBlock& srt::CInfoBlock::copyFrom(const CInfoBlock& obj)
return *this;
}

bool srt::CInfoBlock::operator==(const CInfoBlock& obj)
bool srt::CInfoBlock::operator==(const CInfoBlock& obj) const
{
if (m_iIPversion != obj.m_iIPversion)
return false;
2 changes: 1 addition & 1 deletion srtcore/cache.h
Original file line number Diff line number Diff line change
@@ -253,7 +253,7 @@ class CInfoBlock
CInfoBlock& copyFrom(const CInfoBlock& obj);
CInfoBlock(const CInfoBlock& src) { copyFrom(src); }
CInfoBlock& operator=(const CInfoBlock& src) { return copyFrom(src); }
bool operator==(const CInfoBlock& obj);
bool operator==(const CInfoBlock& obj) const;
CInfoBlock* clone();
int getKey();
void release() {}
4 changes: 2 additions & 2 deletions srtcore/channel.cpp
Original file line number Diff line number Diff line change
@@ -754,7 +754,7 @@ int srt::CChannel::sendto(const sockaddr_any& addr, CPacket& packet, const socka
}
mh.msg_flags = 0;

const int res = ::sendmsg(m_iSocket, &mh, 0);
const int res = (int)::sendmsg(m_iSocket, &mh, 0);
#else
DWORD size = (DWORD)(CPacket::HDR_SIZE + packet.getLength());
int addrsize = addr.size();
@@ -821,7 +821,7 @@ srt::EReadStatus srt::CChannel::recvfrom(sockaddr_any& w_addr, CPacket& w_packet

mh.msg_flags = 0;

recv_size = ::recvmsg(m_iSocket, (&mh), 0);
recv_size = (int)::recvmsg(m_iSocket, (&mh), 0);
msg_flags = mh.msg_flags;
}

6 changes: 5 additions & 1 deletion srtcore/common.h
Original file line number Diff line number Diff line change
@@ -1410,7 +1410,11 @@ inline std::string SrtVersionString(int version)
int major = version/0x10000;

char buf[20];
sprintf(buf, "%d.%d.%d", major, minor, patch);
#if defined(_MSC_VER) && _MSC_VER < 1900
_snprintf(buf, sizeof(buf) - 1, "%d.%d.%d", major, minor, patch);
#else
snprintf(buf, sizeof(buf), "%d.%d.%d", major, minor, patch);
#endif
return buf;
}

6 changes: 5 additions & 1 deletion srtcore/crypto.cpp
Original file line number Diff line number Diff line change
@@ -61,7 +61,11 @@ std::string KmStateStr(SRT_KM_STATE state)
default:
{
char buf[256];
sprintf(buf, "??? (%d)", state);
#if defined(_MSC_VER) && _MSC_VER < 1900
_snprintf(buf, sizeof(buf) - 1, "??? (%d)", state);
#else
snprintf(buf, sizeof(buf), "??? (%d)", state);
#endif
return buf;
}
}
10 changes: 5 additions & 5 deletions srtcore/epoll.cpp
Original file line number Diff line number Diff line change
@@ -661,23 +661,23 @@ int srt::CEPoll::wait(const int eid, set<SRTSOCKET>* readfds, set<SRTSOCKET>* wr

#elif defined(BSD) || TARGET_OS_MAC
struct timespec tmout = {0, 0};
const int max_events = ed.m_sLocals.size();
const int max_events = (int)ed.m_sLocals.size();
SRT_ASSERT(max_events > 0);
srt::FixedArray<struct kevent> ke(max_events);

int nfds = kevent(ed.m_iLocalID, NULL, 0, ke.data(), ke.size(), &tmout);
int nfds = kevent(ed.m_iLocalID, NULL, 0, ke.data(), (int)ke.size(), &tmout);
IF_HEAVY_LOGGING(const int prev_total = total);

for (int i = 0; i < nfds; ++ i)
{
if ((NULL != lrfds) && (ke[i].filter == EVFILT_READ))
{
lrfds->insert(ke[i].ident);
lrfds->insert((int)ke[i].ident);
++ total;
}
if ((NULL != lwfds) && (ke[i].filter == EVFILT_WRITE))
{
lwfds->insert(ke[i].ident);
lwfds->insert((int)ke[i].ident);
++ total;
}
}
@@ -703,7 +703,7 @@ int srt::CEPoll::wait(const int eid, set<SRTSOCKET>* readfds, set<SRTSOCKET>* wr
if (lwfds)
FD_SET(*i, &rqwritefds);
if ((int)*i > max_fd)
max_fd = *i;
max_fd = (int)*i;
}

IF_HEAVY_LOGGING(const int prev_total = total);
12 changes: 6 additions & 6 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
@@ -231,7 +231,7 @@ CUDTGroup::SocketData* CUDTGroup::add(SocketData data)
gli_t end = m_Group.end();
if (m_iMaxPayloadSize == -1)
{
int plsize = data.ps->core().OPT_PayloadSize();
int plsize = (int)data.ps->core().OPT_PayloadSize();
HLOGC(gmlog.Debug,
log << "CUDTGroup::add: taking MAX payload size from socket @" << data.ps->m_SocketID << ": " << plsize
<< " " << (plsize ? "(explicit)" : "(unspecified = fallback to 1456)"));
@@ -548,7 +548,7 @@ void CUDTGroup::deriveSettings(CUDT* u)
if (u->m_config.CryptoSecret.len)
{
string password((const char*)u->m_config.CryptoSecret.str, u->m_config.CryptoSecret.len);
m_config.push_back(ConfigItem(SRTO_PASSPHRASE, password.c_str(), password.size()));
m_config.push_back(ConfigItem(SRTO_PASSPHRASE, password.c_str(), (int)password.size()));
}

IM(SRTO_KMREFRESHRATE, uKmRefreshRatePkt);
@@ -557,7 +557,7 @@ void CUDTGroup::deriveSettings(CUDT* u)
string cc = u->m_CongCtl.selected_name();
if (cc != "live")
{
m_config.push_back(ConfigItem(SRTO_CONGESTION, cc.c_str(), cc.size()));
m_config.push_back(ConfigItem(SRTO_CONGESTION, cc.c_str(), (int)cc.size()));
}

// NOTE: This is based on information extracted from the "semi-copy-constructor" of CUDT class.
@@ -1718,7 +1718,7 @@ int CUDTGroup::getGroupData_LOCKED(SRT_SOCKGROUPDATA* pdata, size_t* psize)
copyGroupData(*d, (pdata[i]));
}

return m_Group.size();
return (int)m_Group.size();
}

// [[using locked(this->m_GroupLock)]]
@@ -3149,7 +3149,7 @@ void CUDTGroup::sendBackup_CheckUnstableSockets(SendBackupCtx& w_sendBackupCtx,
<< " is qualified as unstable, but does not have the 'unstable since' timestamp. Still marking for closure.");
}

const int unstable_for_ms = count_milliseconds(currtime - sock.m_tsUnstableSince);
const int unstable_for_ms = (int)count_milliseconds(currtime - sock.m_tsUnstableSince);
if (unstable_for_ms < sock.peerIdleTimeout_ms())
continue;

@@ -3864,7 +3864,7 @@ int CUDTGroup::sendBackupRexmit(CUDT& core, SRT_MSGCTRL& w_mc)
{
// NOTE: an exception from here will interrupt the loop
// and will be caught in the upper level.
stat = core.sendmsg2(i->data, i->size, (i->mc));
stat = core.sendmsg2(i->data, (int)i->size, (i->mc));
if (stat == -1)
{
// Stop sending if one sending ended up with error
6 changes: 5 additions & 1 deletion srtcore/logging.h
Original file line number Diff line number Diff line change
@@ -359,7 +359,11 @@ struct LogDispatcher::Proxy
{
char buf[512];

vsprintf(buf, fmts, ap);
#if defined(_MSC_VER) && _MSC_VER < 1900
_vsnprintf(buf, sizeof(buf) - 1, fmts, ap);
#else
vsnprintf(buf, sizeof(buf), fmts, ap);
#endif
size_t len = strlen(buf);
if ( buf[len-1] == '\n' )
{
2 changes: 1 addition & 1 deletion srtcore/packet.h
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ const int32_t LOSSDATA_SEQNO_RANGE_LAST = 0, LOSSDATA_SEQNO_SOLO = 0;

inline int32_t CreateControlSeqNo(UDTMessageType type)
{
return SEQNO_CONTROL::mask | SEQNO_MSGTYPE::wrap(size_t(type));
return SEQNO_CONTROL::mask | SEQNO_MSGTYPE::wrap(uint32_t(type));
}

inline int32_t CreateControlExtSeqNo(int exttype)
2 changes: 1 addition & 1 deletion srtcore/packetfilter.cpp
Original file line number Diff line number Diff line change
@@ -169,7 +169,7 @@ void srt::PacketFilter::receive(CUnit* unit, std::vector<CUnit*>& w_incoming, lo
InsertRebuilt(w_incoming, m_unitq);

ScopedLock lg(m_parent->m_StatsLock);
m_parent->m_stats.rcvr.suppliedByFilter.count(nsupply);
m_parent->m_stats.rcvr.suppliedByFilter.count((uint32_t)nsupply);
}

// Now that all units have been filled as they should be,
3 changes: 0 additions & 3 deletions srtcore/platform_sys.h
Original file line number Diff line number Diff line change
@@ -40,9 +40,6 @@

#include <stdint.h>
#include <inttypes.h>
#if defined(_MSC_VER)
#pragma warning(disable: 4251 26812)
#endif
#else

#if defined(__APPLE__) && __APPLE__
2 changes: 1 addition & 1 deletion srtcore/srt_compat.c
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ extern const char * SysStrError(int errnum, char * buf, size_t buflen)
// your compilation fails when you use wide characters.
// The problem is that when TCHAR != char, then the buffer written this way
// would have to be converted to ASCII, not just copied by strncpy.
FormatMessage(0
FormatMessageA(0
| FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
6 changes: 5 additions & 1 deletion srtcore/sync.cpp
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ std::string FormatTimeSys(const steady_clock::time_point& timestamp)
const steady_clock::time_point now_timestamp = steady_clock::now();
const int64_t delta_us = count_microseconds(timestamp - now_timestamp);
const int64_t delta_s =
floor((static_cast<int64_t>(count_microseconds(now_timestamp.time_since_epoch()) % 1000000) + delta_us) / 1000000.0);
static_cast<int64_t>(floor((static_cast<double>(count_microseconds(now_timestamp.time_since_epoch()) % 1000000) + delta_us) / 1000000.0));
const time_t tt = now_s + delta_s;
struct tm tm = SysLocalTime(tt); // in seconds
char tmp_buf[512];
@@ -94,7 +94,11 @@ bool StartThread(CThread& th, void* (*f) (void*), void* args, const string& name
th.create_thread(f, args);
#endif
}
#if ENABLE_HEAVY_LOGGING
catch (const CThreadException& e)
#else
catch (const CThreadException&)
#endif
{
HLOGC(inlog.Debug, log << name << ": failed to start thread. " << e.what());
return false;
Loading