Skip to content

Commit

Permalink
[core] Minor warning fixes (C4267): type conversion with possible los…
Browse files Browse the repository at this point in the history
…s of data (#1710)
  • Loading branch information
maxsharabayko authored Dec 23, 2020
1 parent a165d45 commit df25ca8
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ int CUDTUnited::groupConnect(CUDTGroup* pg, SRT_SOCKGROUPCONFIG* targets, int ar
{
HLOGC(aclog.Debug, log << "groupConnect: OPTION @" << sid << " #" << g.m_config[i].so);
error_reason = "setting group-derived option: #" + Sprint(g.m_config[i].so);
ns->core().setOpt(g.m_config[i].so, &g.m_config[i].value[0], g.m_config[i].value.size());
ns->core().setOpt(g.m_config[i].so, &g.m_config[i].value[0], (int) g.m_config[i].value.size());
}

// Do not try to set a user option if failed already.
Expand Down Expand Up @@ -1700,7 +1700,7 @@ int CUDTUnited::groupConnect(CUDTGroup* pg, SRT_SOCKGROUPCONFIG* targets, int ar
break;
}
HLOGC(aclog.Debug, log << "groupConnect: first connection, applying EPOLL WAITING.");
int len = spawned.size();
int len = (int) spawned.size();
vector<SRTSOCKET> ready(spawned.size());
const int estat = srt_epoll_wait(eid,
NULL, NULL, // IN/ACCEPT
Expand Down
4 changes: 2 additions & 2 deletions srtcore/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ int CRcvBuffer::readBufferToFile(fstream& ofs, int len)
#if ENABLE_LOGGING
trace_seq = pkt.getSeqNo();
#endif
const int pktlen = pkt.getLength();
const int pktlen = (int) pkt.getLength();
const int remain_pktlen = pktlen - m_iNotch;

const int unitsize = std::min(remain_pktlen, rs);
Expand Down Expand Up @@ -2295,7 +2295,7 @@ bool CRcvBuffer::scanMsg(int& w_p, int& w_q, bool& w_passack)
}

rmpkts++;
rmbytes += freeUnitAt(m_iStartPos);
rmbytes += (int) freeUnitAt((size_t) m_iStartPos);

m_iStartPos = shiftFwd(m_iStartPos);
}
Expand Down
20 changes: 10 additions & 10 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ bool SRT_SocketOptionObject::add(SRT_SOCKOPT optname, const void* optval, size_t
unsigned char* mem = new unsigned char[headersize + payload];
SingleOption* option = reinterpret_cast<SingleOption*>(mem);
option->option = optname;
option->length = optlen;
option->length = (uint16_t) optlen;
memcpy(option->storage, optval, optlen);

options.push_back(option);
Expand Down Expand Up @@ -1872,7 +1872,7 @@ size_t CUDT::fillHsExtConfigString(uint32_t* pcmdspec, int cmd, const string& st
// Preswap to little endian (in place due to possible padding zeros)
HtoILA((space), space, wordsize);

*pcmdspec = HS_CMDSPEC_CMD::wrap(cmd) | HS_CMDSPEC_SIZE::wrap(wordsize);
*pcmdspec = HS_CMDSPEC_CMD::wrap(cmd) | HS_CMDSPEC_SIZE::wrap((uint32_t) wordsize);

return wordsize;
}
Expand Down Expand Up @@ -1932,7 +1932,7 @@ size_t CUDT::fillHsExtKMREQ(uint32_t* pcmdspec, size_t ki)
size_t ra_size = (msglen / sizeof(uint32_t)) + (msglen % sizeof(uint32_t) ? 1 : 0);

// Store the CMD + SIZE in the next field
*pcmdspec = HS_CMDSPEC_CMD::wrap(SRT_CMD_KMREQ) | HS_CMDSPEC_SIZE::wrap(ra_size);
*pcmdspec = HS_CMDSPEC_CMD::wrap(SRT_CMD_KMREQ) | HS_CMDSPEC_SIZE::wrap((uint32_t) ra_size);

// Copy the key - do the endian inversion because another endian inversion
// will be done for every control message before sending, and this KM message
Expand Down Expand Up @@ -1984,7 +1984,7 @@ size_t CUDT::fillHsExtKMRSP(uint32_t* pcmdspec, const uint32_t* kmdata, size_t k
keydata = reinterpret_cast<const uint32_t *>(kmdata);
}

*pcmdspec = HS_CMDSPEC_CMD::wrap(SRT_CMD_KMRSP) | HS_CMDSPEC_SIZE::wrap(ra_size);
*pcmdspec = HS_CMDSPEC_CMD::wrap(SRT_CMD_KMRSP) | HS_CMDSPEC_SIZE::wrap((uint32_t) ra_size);
HLOGC(cnlog.Debug,
log << "createSrtHandshake: KMRSP: applying returned key length="
<< ra_size); // XXX INSECURE << " words: [" << FormatBinaryString((uint8_t*)kmdata,
Expand Down Expand Up @@ -2230,7 +2230,7 @@ bool CUDT::createSrtHandshake(
// NOTE: so far, ra_size is m_iMaxSRTPayloadSize expressed in number of elements.
// WILL BE CHANGED HERE.
ra_size = fillSrtHandshake((p + offset), total_ra_size - offset, srths_cmd, HS_VERSION_SRT1);
*pcmdspec = HS_CMDSPEC_CMD::wrap(srths_cmd) | HS_CMDSPEC_SIZE::wrap(ra_size);
*pcmdspec = HS_CMDSPEC_CMD::wrap(srths_cmd) | HS_CMDSPEC_SIZE::wrap((uint32_t) ra_size);

HLOGC(cnlog.Debug,
log << "createSrtHandshake: after HSREQ: offset=" << offset << " HSREQ size=" << ra_size
Expand Down Expand Up @@ -9286,7 +9286,7 @@ std::pair<int, steady_clock::time_point> CUDT::packData(CPacket& w_packet)
m_PacketFilter.packControlPacket(m_iSndCurrSeqNo, m_pCryptoControl->getSndCryptoFlags(), (w_packet)))
{
HLOGC(qslog.Debug, log << "filter: filter/CTL packet ready - packing instead of data.");
payload = w_packet.getLength();
payload = (int) w_packet.getLength();
reason = "filter";
filter_ctl_pkt = true; // Mark that this packet ALREADY HAS timestamp field and it should not be set

Expand Down Expand Up @@ -9454,7 +9454,7 @@ std::pair<int, steady_clock::time_point> CUDT::packData(CPacket& w_packet)
// Encryption failed
return std::make_pair(-1, enter_time);
}
payload = w_packet.getLength(); /* Cipher may change length */
payload = (int) w_packet.getLength(); /* Cipher may change length */
reason += " (encrypted)";
}

Expand Down Expand Up @@ -9583,7 +9583,7 @@ void CUDT::sendLossReport(const std::vector<std::pair<int32_t, int32_t> > &loss_

if (!seqbuffer.empty())
{
sendCtrl(UMSG_LOSSREPORT, NULL, &seqbuffer[0], seqbuffer.size());
sendCtrl(UMSG_LOSSREPORT, NULL, &seqbuffer[0], (int) seqbuffer.size());
}
}

Expand Down Expand Up @@ -9724,7 +9724,7 @@ int CUDT::processData(CUnit* in_unit)
updateCC(TEV_RECEIVE, EventVariant(&packet));
++m_iPktCount;

const int pktsz = packet.getLength();
const int pktsz = (int) packet.getLength();
// Update time information
// XXX Note that this adds the byte size of a packet
// of which we don't yet know as to whether this has
Expand Down Expand Up @@ -10250,7 +10250,7 @@ int CUDT::processData(CUnit* in_unit)
}
if (!lossdata.empty())
{
sendCtrl(UMSG_LOSSREPORT, NULL, &lossdata[0], lossdata.size());
sendCtrl(UMSG_LOSSREPORT, NULL, &lossdata[0], (int) lossdata.size());
}

// was_sent_in_order means either of:
Expand Down
4 changes: 2 additions & 2 deletions srtcore/fec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void FECFilterBuiltin::ConfigureGroup(Group& g, int32_t seqno, size_t gstep, siz

void FECFilterBuiltin::ResetGroup(Group& g)
{
int32_t new_seq_base = CSeqNo::incseq(g.base, int(g.drop));
const int32_t new_seq_base = CSeqNo::incseq(g.base, int(g.drop));

HLOGC(pflog.Debug, log << "FEC: ResetGroup (step=" << g.step << "): base %" << g.base << " -> %" << new_seq_base);

Expand Down Expand Up @@ -386,6 +386,7 @@ void FECFilterBuiltin::feedSource(CPacket& packet)
return;
}

SRT_ASSERT(vert_off >= 0);
int vert_pos = vert_off / int(sizeRow());

HLOGC(pflog.Debug, log << "FEC:feedSource: %" << packet.getSeqNo()
Expand Down Expand Up @@ -2472,4 +2473,3 @@ size_t FECFilterBuiltin::ExtendColumns(size_t colgx)

return colgx;
}

2 changes: 1 addition & 1 deletion srtcore/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void CPacket::setLength(size_t len)
m_PacketVector[PV_DATA].setLength(len);
}

void CPacket::pack(UDTMessageType pkttype, const int32_t* lparam, void* rparam, int size)
void CPacket::pack(UDTMessageType pkttype, const int32_t* lparam, void* rparam, size_t size)
{
// Set (bit-0 = 1) and (bit-1~15 = type)
setControl(pkttype);
Expand Down
2 changes: 1 addition & 1 deletion srtcore/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ friend class CRcvQueue;
/// @param rparam [in] pointer to the second data structure, explained by the packet type.
/// @param size [in] size of rparam, in number of bytes;

void pack(UDTMessageType pkttype, const int32_t* lparam = NULL, void* rparam = NULL, int size = 0);
void pack(UDTMessageType pkttype, const int32_t* lparam = NULL, void* rparam = NULL, size_t size = 0);

/// Read the packet vector.
/// @return Pointer to the packet vector.
Expand Down
14 changes: 7 additions & 7 deletions srtcore/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ CRcvQueue::CRcvQueue()
, m_pHash(NULL)
, m_pChannel(NULL)
, m_pTimer(NULL)
, m_iPayloadSize()
, m_szPayloadSize()
, m_bClosing(false)
, m_LSLock()
, m_pListener(NULL)
Expand Down Expand Up @@ -1175,11 +1175,11 @@ CRcvQueue::~CRcvQueue()
#endif


void CRcvQueue::init(int qsize, int payload, int version, int hsize, CChannel *cc, CTimer *t)
void CRcvQueue::init(int qsize, size_t payload, int version, int hsize, CChannel *cc, CTimer *t)
{
m_iPayloadSize = payload;
m_szPayloadSize = payload;

m_UnitQueue.init(qsize, payload, version);
m_UnitQueue.init(qsize, (int) payload, version);

m_pHash = new CHash;
m_pHash->init(hsize);
Expand Down Expand Up @@ -1362,8 +1362,8 @@ EReadStatus CRcvQueue::worker_RetrieveUnit(int32_t& w_id, CUnit*& w_unit, sockad
{
// no space, skip this packet
CPacket temp;
temp.m_pcData = new char[m_iPayloadSize];
temp.setLength(m_iPayloadSize);
temp.m_pcData = new char[m_szPayloadSize];
temp.setLength(m_szPayloadSize);
THREAD_PAUSED();
EReadStatus rst = m_pChannel->recvfrom((w_addr), (temp));
THREAD_RESUMED();
Expand All @@ -1376,7 +1376,7 @@ EReadStatus CRcvQueue::worker_RetrieveUnit(int32_t& w_id, CUnit*& w_unit, sockad
return rst == RST_ERROR ? RST_ERROR : RST_AGAIN;
}

w_unit->m_Packet.setLength(m_iPayloadSize);
w_unit->m_Packet.setLength(m_szPayloadSize);

// reading next incoming packet, recvfrom returns -1 is nothing has been received
THREAD_PAUSED();
Expand Down
4 changes: 2 additions & 2 deletions srtcore/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ friend class CUDTUnited;
/// @param [in] c UDP channel to be associated to the queue
/// @param [in] t timer

void init(int size, int payload, int version, int hsize, CChannel* c, srt::sync::CTimer* t);
void init(int size, size_t payload, int version, int hsize, CChannel* c, srt::sync::CTimer* t);

/// Read a packet for a specific UDT socket id.
/// @param [in] id Socket ID
Expand Down Expand Up @@ -493,7 +493,7 @@ friend class CUDTUnited;
CChannel* m_pChannel; // UDP channel for receving packets
srt::sync::CTimer* m_pTimer; // shared timer with the snd queue

int m_iPayloadSize; // packet payload size
size_t m_szPayloadSize; // packet payload size

volatile bool m_bClosing; // closing the worker
#if ENABLE_LOGGING
Expand Down
2 changes: 1 addition & 1 deletion srtcore/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class CPktTimeWindow: CPktTimeWindowTools
// the ETH+IP+UDP+SRT header part elliminates the constant packet delivery time influence.
//
const size_t pktsz = pkt.getLength();
m_aProbeWindow[m_iProbeWindowPtr] = pktsz ? timediff_times_pl_size / pktsz : int(timediff);
m_aProbeWindow[m_iProbeWindowPtr] = pktsz ? int(timediff_times_pl_size / pktsz) : int(timediff);

// OLD CODE BEFORE BSTATS:
// record the probing packets interval
Expand Down

0 comments on commit df25ca8

Please sign in to comment.