diff --git a/haicrypt/cryspr-mbedtls.c b/haicrypt/cryspr-mbedtls.c index c22016293..4714f6b2e 100644 --- a/haicrypt/cryspr-mbedtls.c +++ b/haicrypt/cryspr-mbedtls.c @@ -19,6 +19,8 @@ written by GnuTLS/Nettle CRYSPR/4SRT (CRYypto Service PRovider for SRT) *****************************************************************************/ +#include "platform_sys.h" + #include "hcrypt.h" #include @@ -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); diff --git a/haicrypt/cryspr.c b/haicrypt/cryspr.c index 9e5c42897..a532be77a 100644 --- a/haicrypt/cryspr.c +++ b/haicrypt/cryspr.c @@ -17,6 +17,8 @@ written by CRYSPR/4SRT Initial implementation. *****************************************************************************/ +#include "platform_sys.h" + #include "hcrypt.h" #include "cryspr.h" diff --git a/haicrypt/hcrypt.h b/haicrypt/hcrypt.h index 2e5b938bd..34e744e8a 100644 --- a/haicrypt/hcrypt.h +++ b/haicrypt/hcrypt.h @@ -32,10 +32,6 @@ written by #ifdef _WIN32 #include #include - #if defined(_MSC_VER) - #pragma warning(disable:4267) - #pragma warning(disable:4018) - #endif #else #include #endif diff --git a/haicrypt/hcrypt_ctx_rx.c b/haicrypt/hcrypt_ctx_rx.c index f1024fb2d..31b814480 100644 --- a/haicrypt/hcrypt_ctx_rx.c +++ b/haicrypt/hcrypt_ctx_rx.c @@ -19,6 +19,8 @@ written by Adaptation for SRT. *****************************************************************************/ +#include "platform_sys.h" + #include /* 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 } diff --git a/haicrypt/hcrypt_ctx_tx.c b/haicrypt/hcrypt_ctx_tx.c index df0dc0fd9..622558f12 100644 --- a/haicrypt/hcrypt_ctx_tx.c +++ b/haicrypt/hcrypt_ctx_tx.c @@ -19,6 +19,8 @@ written by Adaptation for SRT. *****************************************************************************/ +#include "platform_sys.h" + #include /* memcpy */ #ifdef _WIN32 #include @@ -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); diff --git a/haicrypt/hcrypt_msg.h b/haicrypt/hcrypt_msg.h index ab43dbb4f..33a9522f9 100644 --- a/haicrypt/hcrypt_msg.h +++ b/haicrypt/hcrypt_msg.h @@ -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 */ diff --git a/haicrypt/hcrypt_rx.c b/haicrypt/hcrypt_rx.c index 54c9ae039..75c9a7a44 100644 --- a/haicrypt/hcrypt_rx.c +++ b/haicrypt/hcrypt_rx.c @@ -19,6 +19,8 @@ written by Adaptation for SRT. *****************************************************************************/ +#include "platform_sys.h" + #include /* NULL */ #include /* 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; diff --git a/srtcore/buffer_rcv.h b/srtcore/buffer_rcv.h index e35238b3c..b7a80ef32 100644 --- a/srtcore/buffer_rcv.h +++ b/srtcore/buffer_rcv.h @@ -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; } diff --git a/srtcore/cache.cpp b/srtcore/cache.cpp index e4fa90d87..4cda9a70f 100644 --- a/srtcore/cache.cpp +++ b/srtcore/cache.cpp @@ -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; diff --git a/srtcore/cache.h b/srtcore/cache.h index 0dd57ba01..47633706a 100644 --- a/srtcore/cache.h +++ b/srtcore/cache.h @@ -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() {} diff --git a/srtcore/channel.cpp b/srtcore/channel.cpp index 5b0e05e94..31a29092f 100644 --- a/srtcore/channel.cpp +++ b/srtcore/channel.cpp @@ -770,7 +770,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(); @@ -837,7 +837,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; } diff --git a/srtcore/common.h b/srtcore/common.h index 2f1546d22..5f3dd7f18 100644 --- a/srtcore/common.h +++ b/srtcore/common.h @@ -1410,7 +1410,11 @@ inline std::string SrtVersionString(int version) int major = version/0x10000; char buf[22]; - 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; } diff --git a/srtcore/crypto.cpp b/srtcore/crypto.cpp index 152f53eb7..223989199 100644 --- a/srtcore/crypto.cpp +++ b/srtcore/crypto.cpp @@ -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; } } diff --git a/srtcore/epoll.cpp b/srtcore/epoll.cpp index 4040a21be..55211380b 100644 --- a/srtcore/epoll.cpp +++ b/srtcore/epoll.cpp @@ -661,23 +661,23 @@ int srt::CEPoll::wait(const int eid, set* readfds, set* 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 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* readfds, set* 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); diff --git a/srtcore/group.cpp b/srtcore/group.cpp index a3c096a4f..f4dfba1ba 100644 --- a/srtcore/group.cpp +++ b/srtcore/group.cpp @@ -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 diff --git a/srtcore/logging.h b/srtcore/logging.h index 8e41bbe50..91fbc5c31 100644 --- a/srtcore/logging.h +++ b/srtcore/logging.h @@ -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' ) { diff --git a/srtcore/packet.h b/srtcore/packet.h index 72c57a7c4..027d5f0b3 100644 --- a/srtcore/packet.h +++ b/srtcore/packet.h @@ -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) diff --git a/srtcore/packetfilter.cpp b/srtcore/packetfilter.cpp index 1b05c4f4e..37785f43a 100644 --- a/srtcore/packetfilter.cpp +++ b/srtcore/packetfilter.cpp @@ -169,7 +169,7 @@ void srt::PacketFilter::receive(CUnit* unit, std::vector& 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, diff --git a/srtcore/platform_sys.h b/srtcore/platform_sys.h index cb5d0afd9..fae2cc07c 100644 --- a/srtcore/platform_sys.h +++ b/srtcore/platform_sys.h @@ -40,9 +40,6 @@ #include #include - #if defined(_MSC_VER) - #pragma warning(disable: 4251 26812) - #endif #else #if defined(__APPLE__) && __APPLE__ diff --git a/srtcore/srt_compat.c b/srtcore/srt_compat.c index 1473a7b94..8241fadc4 100644 --- a/srtcore/srt_compat.c +++ b/srtcore/srt_compat.c @@ -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, diff --git a/srtcore/sync.cpp b/srtcore/sync.cpp index 7f2bc12ab..a7cebb909 100644 --- a/srtcore/sync.cpp +++ b/srtcore/sync.cpp @@ -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(count_microseconds(now_timestamp.time_since_epoch()) % 1000000) + delta_us) / 1000000.0); + static_cast(floor((static_cast(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; diff --git a/srtcore/window.cpp b/srtcore/window.cpp index b077178c9..46889ecb0 100644 --- a/srtcore/window.cpp +++ b/srtcore/window.cpp @@ -93,7 +93,7 @@ int acknowledge(Seq* r_aSeq, const size_t size, int& r_iHead, int& r_iTail, int3 r_ack = r_aSeq[i].iACK; // Calculate RTT estimate - const int rtt = count_microseconds(currtime - r_aSeq[i].tsTimeStamp); + const int rtt = (int)count_microseconds(currtime - r_aSeq[i].tsTimeStamp); if (i + 1 == r_iHead) { @@ -112,7 +112,7 @@ int acknowledge(Seq* r_aSeq, const size_t size, int& r_iHead, int& r_iTail, int3 } // Head has exceeded the physical window boundary, so it is behind tail - for (int j = r_iTail, n = r_iHead + size; j < n; ++ j) + for (int j = r_iTail, n = r_iHead + (int)size; j < n; ++ j) { // Looking for an identical ACK Seq. No. if (seq == r_aSeq[j % size].iACKSeqNo) @@ -122,7 +122,7 @@ int acknowledge(Seq* r_aSeq, const size_t size, int& r_iHead, int& r_iTail, int3 r_ack = r_aSeq[j].iACK; // Calculate RTT estimate - const int rtt = count_microseconds(currtime - r_aSeq[j].tsTimeStamp); + const int rtt = (int)count_microseconds(currtime - r_aSeq[j].tsTimeStamp); if (j == r_iHead) { @@ -176,7 +176,7 @@ int srt::CPktTimeWindowTools::getPktRcvSpeed_in(const int* window, int* replica, const int* bp = abytes; // median filtering const int* p = window; - for (int i = 0, n = asize; i < n; ++ i) + for (int i = 0, n = (int)asize; i < n; ++ i) { if ((*p < upper) && (*p > lower)) { @@ -192,7 +192,7 @@ int srt::CPktTimeWindowTools::getPktRcvSpeed_in(const int* window, int* replica, if (count > (asize >> 1)) { bytes += (srt::CPacket::SRT_DATA_HDR_SIZE * count); //Add protocol headers to bytes received - bytesps = (unsigned long)ceil(1000000.0 / (double(sum) / double(bytes))); + bytesps = (int)ceil(1000000.0 / (double(sum) / double(bytes))); return (int)ceil(1000000.0 / (sum / count)); } else @@ -240,7 +240,7 @@ int srt::CPktTimeWindowTools::getBandwidth_in(const int* window, int* replica, s // median filtering const int* p = window; - for (int i = 0, n = psize; i < n; ++ i) + for (int i = 0, n = (int)psize; i < n; ++ i) { if ((*p < upper) && (*p > lower)) {