Skip to content

Commit

Permalink
[core] Fixed various compiler warnings on various platforms (#2679).
Browse files Browse the repository at this point in the history
  • Loading branch information
oviano authored Apr 21, 2023
1 parent 59cde53 commit 6fcff6d
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 52 deletions.
7 changes: 5 additions & 2 deletions apps/apputil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ int inet_pton(int af, const char * src, void * dst)
ZeroMemory(&ss, sizeof(ss));

// work around non-const API
strncpy(srcCopy, src, INET6_ADDRSTRLEN + 1);
#ifdef _MSC_VER
strncpy_s(srcCopy, INET6_ADDRSTRLEN + 1, src, _TRUNCATE);
#else
strncpy(srcCopy, src, INET6_ADDRSTRLEN);
srcCopy[INET6_ADDRSTRLEN] = '\0';

#endif
if (WSAStringToAddress(
srcCopy, af, NULL, (struct sockaddr *)&ss, &ssSize) != 0)
{
Expand Down
10 changes: 8 additions & 2 deletions apps/srt-live-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,14 @@ int main(int argc, char** argv)
void TestLogHandler(void* opaque, int level, const char* file, int line, const char* area, const char* message)
{
char prefix[100] = "";
if ( opaque )
strncpy(prefix, (char*)opaque, 99);
if ( opaque ) {
#ifdef _MSC_VER
strncpy_s(prefix, sizeof(prefix), (char*)opaque, _TRUNCATE);
#else
strncpy(prefix, (char*)opaque, sizeof(prefix) - 1);
prefix[sizeof(prefix) - 1] = '\0';
#endif
}
time_t now;
time(&now);
char buf[1024];
Expand Down
18 changes: 9 additions & 9 deletions apps/srt-tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class Tunnel

Tunnel(Tunnelbox* m, std::unique_ptr<Medium>&& acp, std::unique_ptr<Medium>&& clr):
parent_box(m),
med_acp(move(acp)), med_clr(move(clr)),
med_acp(std::move(acp)), med_clr(std::move(clr)),
acp_to_clr(this, med_acp.get(), med_clr.get(), med_acp->id() + ">" + med_clr->id()),
clr_to_acp(this, med_clr.get(), med_acp.get(), med_clr->id() + ">" + med_acp->id())
{
Expand Down Expand Up @@ -649,7 +649,7 @@ void TcpMedium::CreateListener()

sockaddr_any sa = CreateAddr(m_uri.host(), m_uri.portno());

m_socket = socket(sa.get()->sa_family, SOCK_STREAM, IPPROTO_TCP);
m_socket = (int)socket(sa.get()->sa_family, SOCK_STREAM, IPPROTO_TCP);
ConfigurePre();

int stat = ::bind(m_socket, sa.get(), sa.size());
Expand Down Expand Up @@ -694,7 +694,7 @@ unique_ptr<Medium> SrtMedium::Accept()
unique_ptr<Medium> TcpMedium::Accept()
{
sockaddr_any sa;
int s = ::accept(m_socket, (sa.get()), (&sa.syslen()));
int s = (int)::accept(m_socket, (sa.get()), (&sa.syslen()));
if (s == -1)
{
Error(errno, "accept");
Expand Down Expand Up @@ -726,7 +726,7 @@ void SrtMedium::CreateCaller()

void TcpMedium::CreateCaller()
{
m_socket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
m_socket = (int)::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
ConfigurePre();
}

Expand Down Expand Up @@ -850,7 +850,7 @@ Medium::ReadStatus Medium::Read(bytevector& w_output)
size_t pred_size = shift + m_chunk;

w_output.resize(pred_size);
int st = ReadInternal((w_output.data() + shift), m_chunk);
int st = ReadInternal((w_output.data() + shift), (int)m_chunk);
if (st == -1)
{
if (IsErrorAgain())
Expand Down Expand Up @@ -884,7 +884,7 @@ Medium::ReadStatus Medium::Read(bytevector& w_output)

void SrtMedium::Write(bytevector& w_buffer)
{
int st = srt_send(m_socket, w_buffer.data(), w_buffer.size());
int st = srt_send(m_socket, w_buffer.data(), (int)w_buffer.size());
if (st == SRT_ERROR)
{
Error(UDT::getlasterror(), "srt_send");
Expand All @@ -907,7 +907,7 @@ void SrtMedium::Write(bytevector& w_buffer)

void TcpMedium::Write(bytevector& w_buffer)
{
int st = ::send(m_socket, w_buffer.data(), w_buffer.size(), DEF_SEND_FLAG);
int st = ::send(m_socket, w_buffer.data(), (int)w_buffer.size(), DEF_SEND_FLAG);
if (st == -1)
{
Error(errno, "send");
Expand Down Expand Up @@ -971,7 +971,7 @@ struct Tunnelbox
lock_guard<std::mutex> lk(access);
Verb() << "Tunnelbox: Starting tunnel: " << acp->uri() << " <-> " << clr->uri();

tunnels.emplace_back(new Tunnel(this, move(acp), move(clr)));
tunnels.emplace_back(new Tunnel(this, std::move(acp), std::move(clr)));
// Note: after this instruction, acp and clr are no longer valid!
auto& it = tunnels.back();

Expand Down Expand Up @@ -1191,7 +1191,7 @@ int main( int argc, char** argv )
Verb() << "Connected. Establishing pipe.";

// No exception, we are free to pass :)
g_tunnels.install(move(accepted), move(caller));
g_tunnels.install(std::move(accepted), std::move(caller));
}
catch (...)
{
Expand Down
4 changes: 2 additions & 2 deletions apps/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ class UdpCommon

void Setup(string host, int port, map<string,string> attr)
{
m_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
m_sock = (int)socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (m_sock == -1)
Error(SysError(), "UdpCommon::Setup: socket");

Expand Down Expand Up @@ -1144,7 +1144,7 @@ extern unique_ptr<Base> CreateMedium(const string& uri)
}

if (ptr.get())
ptr->uri = move(u);
ptr->uri = std::move(u);

return ptr;
}
Expand Down
6 changes: 3 additions & 3 deletions apps/uriparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void UriParser::Parse(const string& strUrl, DefaultExpect exp)
if (idx != string::npos)
{
m_host = strUrl.substr(0, idx);
iQueryStart = idx + 1;
iQueryStart = (int)(idx + 1);
}
else
{
Expand Down Expand Up @@ -297,12 +297,12 @@ void UriParser::Parse(const string& strUrl, DefaultExpect exp)
if (idx != string::npos)
{
strQueryPair = strUrl.substr(iQueryStart, idx - iQueryStart);
iQueryStart = idx + 1;
iQueryStart = (int)(idx + 1);
}
else
{
strQueryPair = strUrl.substr(iQueryStart, strUrl.size() - iQueryStart);
iQueryStart = idx;
iQueryStart = (int)idx;
}

idx = strQueryPair.find("=");
Expand Down
1 change: 0 additions & 1 deletion haicrypt/cryspr-mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ int crysprMbedtls_AES_CtrCipher( /* AES-CTR128 Encryption */
static CRYSPR_cb *crysprMbedtls_Open(CRYSPR_methods *cryspr, size_t max_len)
{
crysprMbedtls_cb *aes_data;
CRYSPR_cb *cryspr_cb;

aes_data = (crysprMbedtls_cb *)crysprHelper_Open(cryspr, sizeof(crysprMbedtls_cb), max_len);
if (NULL == aes_data) {
Expand Down
10 changes: 5 additions & 5 deletions haicrypt/cryspr-openssl-evp.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int crysprOpenSSL_EVP_AES_SetKey(
CRYSPR_AESCTX* aes_key) /* CRYpto Service PRovider AES Key context */
{
const EVP_CIPHER* cipher = NULL;
int idxKlen = (kstr_len / 8) - 2; /* key_len index in cipher_fnptr array in [0,1,2] range */
int idxKlen = (int)((kstr_len / 8) - 2); /* key_len index in cipher_fnptr array in [0,1,2] range */

switch (cipher_type)
{
Expand Down Expand Up @@ -143,7 +143,7 @@ int crysprOpenSSL_EVP_AES_EcbCipher(bool bEncrypt, /* true:encry
size_t* outlen_p) /* in/out dst len */
{
int nmore = inlen % CRYSPR_AESBLKSZ; /* bytes in last incomplete block */
int nblk = inlen / CRYSPR_AESBLKSZ + (nmore ? 1 : 0); /* blocks including incomplete */
int nblk = (int)(inlen / CRYSPR_AESBLKSZ + (nmore ? 1 : 0)); /* blocks including incomplete */
size_t outsiz = (outlen_p ? *outlen_p : 0);
int c_len = 0, f_len = 0;

Expand Down Expand Up @@ -174,7 +174,7 @@ int crysprOpenSSL_EVP_AES_EcbCipher(bool bEncrypt, /* true:encry
/* update ciphertext, c_len is filled with the length of ciphertext generated,
* cryptoPtr->cipher_in_len is the size of plain/cipher text in bytes
*/
if (!EVP_CipherUpdate(aes_key, out_txt, &c_len, indata, inlen))
if (!EVP_CipherUpdate(aes_key, out_txt, &c_len, indata, (int)inlen))
{
HCRYPT_LOG(LOG_ERR, "EVP_CipherUpdate(%p, out, %d, in, %d) failed\n", aes_key, c_len, inlen);
return -1;
Expand Down Expand Up @@ -227,7 +227,7 @@ int crysprOpenSSL_EVP_AES_CtrCipher(bool bEncrypt, /* true:encry
/* update ciphertext, c_len is filled with the length of ciphertext generated,
* cryptoPtr->cipher_in_len is the size of plain/cipher text in bytes
*/
if (!EVP_CipherUpdate(aes_key, out_txt, &c_len, indata, inlen))
if (!EVP_CipherUpdate(aes_key, out_txt, &c_len, indata, (int)inlen))
{
HCRYPT_LOG(LOG_ERR, "%s\n", "EVP_CipherUpdate() failed");
return -1;
Expand Down Expand Up @@ -341,7 +341,7 @@ int crysprOpenSSL_EVP_KmPbkdf2(CRYSPR_cb* cryspr_cb,
unsigned char* out) /* derived key */
{
(void)cryspr_cb;
int rc = PKCS5_PBKDF2_HMAC_SHA1(passwd, passwd_len, salt, salt_len, itr, key_len, out);
int rc = PKCS5_PBKDF2_HMAC_SHA1(passwd, (int)passwd_len, salt, (int)salt_len, itr, (int)key_len, out);
return (rc == 1 ? 0 : -1);
}

Expand Down
6 changes: 3 additions & 3 deletions haicrypt/cryspr-openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ int crysprOpenSSL_AES_SetKey(
(void)cipher_type;

if (bEncrypt) { /* Encrypt key */
if (AES_set_encrypt_key(kstr, kstr_len * 8, aes_key)) {
if (AES_set_encrypt_key(kstr, (int)(kstr_len * 8), aes_key)) {
HCRYPT_LOG(LOG_ERR, "%s", "AES_set_encrypt_key(kek) failed\n");
return(-1);
}
} else { /* Decrypt key */
if (AES_set_decrypt_key(kstr, kstr_len * 8, aes_key)) {
if (AES_set_decrypt_key(kstr, (int)(kstr_len * 8), aes_key)) {
HCRYPT_LOG(LOG_ERR, "%s", "AES_set_decrypt_key(kek) failed\n");
return(-1);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ int crysprOpenSSL_KmPbkdf2(
unsigned char *out) /* derived key */
{
(void)cryspr_cb;
int rc = PKCS5_PBKDF2_HMAC_SHA1(passwd,passwd_len,salt,salt_len,itr,key_len,out);
int rc = PKCS5_PBKDF2_HMAC_SHA1(passwd,(int)passwd_len,salt,(int)salt_len,itr,(int)key_len,out);
return(rc == 1? 0 : -1);
}

Expand Down
2 changes: 1 addition & 1 deletion haicrypt/hcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ int HaiCrypt_Close(HaiCrypt_Handle hhc)
return rc;
}

int HaiCrypt_IsAESGCM_Supported()
int HaiCrypt_IsAESGCM_Supported(void)
{
#if CRYSPR_HAS_AESGCM
return 1;
Expand Down
6 changes: 4 additions & 2 deletions srtcore/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ modified by
#ifndef INC_SRT_COMMON_H
#define INC_SRT_COMMON_H

#define _CRT_SECURE_NO_WARNINGS 1 // silences windows complaints for sscanf
#include <memory>
#include <cstdlib>
#include <cstdio>
Expand Down Expand Up @@ -1393,8 +1392,11 @@ inline ATR_CONSTEXPR uint32_t SrtVersion(int major, int minor, int patch)
inline int32_t SrtParseVersion(const char* v)
{
int major, minor, patch;
#if defined(_MSC_VER)
int result = sscanf_s(v, "%d.%d.%d", &major, &minor, &patch);
#else
int result = sscanf(v, "%d.%d.%d", &major, &minor, &patch);

#endif
if (result != 3)
{
return 0;
Expand Down
16 changes: 8 additions & 8 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ void srt::CUDT::getOpt(SRT_SOCKOPT optName, void *optval, int &optlen)
}

// Fallback: return from internal data
strcpy(((char*)optval), m_config.sBindToDevice.c_str());
optlen = m_config.sBindToDevice.size();
optlen = (int)m_config.sBindToDevice.copy((char*)optval, (size_t)optlen - 1);
((char*)optval)[optlen] = '\0';
#else
LOGC(smlog.Error, log << "SRTO_BINDTODEVICE is not supported on that platform");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
Expand Down Expand Up @@ -737,16 +737,16 @@ void srt::CUDT::getOpt(SRT_SOCKOPT optName, void *optval, int &optlen)
if (size_t(optlen) < m_config.sStreamName.size() + 1)
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);

strcpy((char *)optval, m_config.sStreamName.c_str());
optlen = (int) m_config.sStreamName.size();
optlen = (int)m_config.sStreamName.copy((char*)optval, (size_t)optlen - 1);
((char*)optval)[optlen] = '\0';
break;

case SRTO_CONGESTION:
if (size_t(optlen) < m_config.sCongestion.size() + 1)
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);

strcpy((char *)optval, m_config.sCongestion.c_str());
optlen = (int) m_config.sCongestion.size();
optlen = (int)m_config.sCongestion.copy((char*)optval, (size_t)optlen - 1);
((char*)optval)[optlen] = '\0';
break;

case SRTO_MESSAGEAPI:
Expand Down Expand Up @@ -805,8 +805,8 @@ void srt::CUDT::getOpt(SRT_SOCKOPT optName, void *optval, int &optlen)
if (size_t(optlen) < m_config.sPacketFilterConfig.size() + 1)
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);

strcpy((char *)optval, m_config.sPacketFilterConfig.c_str());
optlen = (int) m_config.sPacketFilterConfig.size();
optlen = (int)m_config.sPacketFilterConfig.copy((char*)optval, (size_t)optlen - 1);
((char*)optval)[optlen] = '\0';
break;

case SRTO_RETRANSMITALGO:
Expand Down
5 changes: 4 additions & 1 deletion srtcore/epoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ class CUDTGroup;

class CEPollDesc
{
#ifdef __GNUG__
const int m_iID; // epoll ID

#else
const int m_iID SRT_ATR_UNUSED; // epoll ID
#endif
struct Wait;

struct Notice: public SRT_EPOLL_EVENT
Expand Down
12 changes: 6 additions & 6 deletions srtcore/fec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,13 @@ void FECFilterBuiltin::ConfigureColumns(Container& which, int32_t isn)
{
offset = col + 1; // +1 because we want it for the next column
HLOGC(pflog.Debug, log << "ConfigureColumns: [" << (col+1) << "]... (resetting to row 0: +"
<< offset << " %" << CSeqNo::incseq(isn, offset) << ")");
<< offset << " %" << CSeqNo::incseq(isn, (int32_t)offset) << ")");
}
else
{
offset += 1 + sizeRow();
HLOGC(pflog.Debug, log << "ConfigureColumns: [" << (col+1) << "] ... (continue +"
<< offset << " %" << CSeqNo::incseq(isn, offset) << ")");
<< offset << " %" << CSeqNo::incseq(isn, (int32_t)offset) << ")");
}
}
}
Expand Down Expand Up @@ -1129,10 +1129,10 @@ static void DebugPrintCells(int32_t base, const std::deque<bool>& cells, size_t
for ( ; i < cells.size(); i += row_size )
{
std::ostringstream os;
os << "cell[" << i << "-" << (i+row_size-1) << "] %" << CSeqNo::incseq(base, i) << ":";
os << "cell[" << i << "-" << (i+row_size-1) << "] %" << CSeqNo::incseq(base, (int32_t)i) << ":";
for (size_t y = 0; y < row_size; ++y)
{
os << " " << CellMark(cells, i+y);
os << " " << CellMark(cells, (int)(i+y));
}
LOGP(pflog.Debug, os.str());
}
Expand Down Expand Up @@ -1953,7 +1953,7 @@ void FECFilterBuiltin::RcvCheckDismissColumn(int32_t seq, int colgx, loss_seqs_t
{
HLOGC(pflog.Debug, log << "FEC/V: ... [" << i << "] base=%"
<< pg.base << " TOO EARLY (last=%"
<< CSeqNo::incseq(pg.base, (sizeCol()-1)*sizeRow())
<< CSeqNo::incseq(pg.base, (int32_t)((sizeCol()-1)*sizeRow()))
<< ")");
continue;
}
Expand All @@ -1964,7 +1964,7 @@ void FECFilterBuiltin::RcvCheckDismissColumn(int32_t seq, int colgx, loss_seqs_t

HLOGC(pflog.Debug, log << "FEC/V: ... [" << i << "] base=%"
<< pg.base << " - PAST last=%"
<< CSeqNo::incseq(pg.base, (sizeCol()-1)*sizeRow())
<< CSeqNo::incseq(pg.base, (int32_t)((sizeCol()-1)*sizeRow()))
<< " - collecting losses.");

pg.dismissed = true; // mark irrecover already collected
Expand Down
18 changes: 14 additions & 4 deletions srtcore/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,24 @@ struct SRT_API LogDispatcher

// See Logger::Logger; we know this has normally 2 characters,
// except !!FATAL!!, which has 9. Still less than 32.
strcpy(prefix, your_pfx);

// If the size of the FA name together with severity exceeds the size,
// just skip the former.
if (logger_pfx && strlen(prefix) + strlen(logger_pfx) + 1 < MAX_PREFIX_SIZE)
{
strcat(prefix, ":");
strcat(prefix, logger_pfx);
#if defined(_MSC_VER) && _MSC_VER < 1900
_snprintf(prefix, MAX_PREFIX_SIZE, "%s:%s", your_pfx, logger_pfx);
#else
snprintf(prefix, MAX_PREFIX_SIZE + 1, "%s:%s", your_pfx, logger_pfx);
#endif
}
else
{
#ifdef _MSC_VER
strncpy_s(prefix, MAX_PREFIX_SIZE + 1, your_pfx, _TRUNCATE);
#else
strncpy(prefix, your_pfx, MAX_PREFIX_SIZE);
prefix[MAX_PREFIX_SIZE] = '\0';
#endif
}
}

Expand Down
Loading

0 comments on commit 6fcff6d

Please sign in to comment.