Skip to content

Made implicit typecasts explicit to eliminate compiler warnings #15

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bnlib/bnprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static int getAsciiDigit( uint32_t *d, int radix, char c )
int
bnReadAscii(struct BigNum *X, char *s, int radix)
{
int slen = strlen(s);
int slen = (int)strlen(s);
int i, neg = 0;
uint32_t d;

Expand Down
27 changes: 14 additions & 13 deletions bnlib/ec/ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ static void curveCommonPrealloc(EcCurve *curve)

/* The set_bit allocates enough memory to hold maximum values */
/* Initialize scratchpad variables before use */
bnPrealloc(curve->S1, maxBits);
bnPrealloc(curve->U1, maxBits);
bnPrealloc(curve->H, maxBits);
bnPrealloc(curve->R, maxBits);
bnPrealloc(curve->S1, maxBits);
bnPrealloc(curve->t1, maxBits);
bnPrealloc(curve->t2, maxBits);
bnPrealloc(curve->t3, maxBits);
bnPrealloc(curve->S1, (unsigned int)maxBits);
bnPrealloc(curve->U1, (unsigned int)maxBits);
bnPrealloc(curve->H, (unsigned int)maxBits);
bnPrealloc(curve->R, (unsigned int)maxBits);
bnPrealloc(curve->S1, (unsigned int)maxBits);
bnPrealloc(curve->t1, (unsigned int)maxBits);
bnPrealloc(curve->t2, (unsigned int)maxBits);
bnPrealloc(curve->t3, (unsigned int)maxBits);
}

int ecGetCurveNistECp(Curves curveId, EcCurve *curve)
Expand Down Expand Up @@ -332,6 +332,7 @@ int ecGetCurveNistECp(Curves curveId, EcCurve *curve)

case NIST256P:
cd = &nist256;
curve->modOp = newMod256; // avoids unused function warning
curve->modOp = bnMod;
break;

Expand Down Expand Up @@ -980,7 +981,7 @@ static int _random(unsigned char *output, size_t len)
#include <cryptcommon/ZrtpRandom.h>
static int _random(unsigned char *output, size_t len)
{
return zrtp_getRandomData(output, len);
return zrtp_getRandomData(output, (uint32_t)len);
}
#endif

Expand Down Expand Up @@ -1008,7 +1009,7 @@ static int ecGenerateRandomNumberNist(const EcCurve *curve, BigNum *d)
while (!bnCmpQ(d, 0)) {
/* use _random function */
_random(ran, randomBytes);
bnInsertBigBytes(&c, ran, 0, randomBytes);
bnInsertBigBytes(&c, ran, 0, (unsigned int)randomBytes);
bnMod(d, &c, &nMinusOne);
bnAddMod_(d, mpiOne, curve->p);
}
Expand Down Expand Up @@ -1671,11 +1672,11 @@ static int newMod521(BigNum *r, const BigNum *a, const BigNum *modulo)
}
modSize = bnBytes(modulo);

bnExtractBigBytes(a, buf1, 0, modSize*2); /* a must be less modulo^2 */
bnExtractBigBytes(a, buf1, 0, (unsigned int)modSize*2); /* a must be less modulo^2 */
buf1[modSize] &= 1; /* clear all bits except least significat */

bnRShift(r, 521);
bnExtractBigBytes(r, buf2, 0, modSize*2);
bnExtractBigBytes(r, buf2, 0, (unsigned int)modSize*2);
buf2[modSize] &= 1;

p1 = &buf2[131]; /* p1 is pointer to A0 */
Expand All @@ -1685,7 +1686,7 @@ static int newMod521(BigNum *r, const BigNum *a, const BigNum *modulo)
ac += *p1 + *p2--; *p1-- = ac; ac >>= 8;
}
bnSetQ(r, 0);
bnInsertBigBytes(r, p1+1, 0, modSize);
bnInsertBigBytes(r, p1+1, 0, (unsigned int)modSize);

while (bnCmp(r, modulo) >= 0) {
bnSub(r, modulo);
Expand Down
21 changes: 8 additions & 13 deletions clients/tivi/CtZrtpStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
// #define DEBUG_CTSTREAM
#ifdef DEBUG_CTSTREAM
static char debBuf[500];
#define DEBUG(deb) deb
#define T_DEBUG(deb) deb
#else
#define DEBUG(deb)
#define T_DEBUG(deb)
#endif

static TimeoutProvider<std::string, CtZrtpStream*>* staticTimeoutProvider = NULL;
Expand Down Expand Up @@ -174,11 +174,6 @@ bool CtZrtpStream::processOutgoingRtp(uint8_t *buffer, size_t length, size_t *ne
*newLength = length;
// Check if ZRTP engine is started and check states to determine if we should send the RTP packet.
// Do not send in states: CommitSent, WaitDHPart2, WaitConfirm1, WaitConfirm2, WaitConfAck
// if (started && (zrtpEngine->inState(CommitSent) || zrtpEngine->inState(WaitDHPart2) || zrtpEngine->inState(WaitConfirm1) ||
// zrtpEngine->inState(WaitConfirm2) || zrtpEngine->inState(WaitConfAck))) {
// ZrtpRandom::addEntropy(buffer, length);
// return false;
// }
if (useSdesForMedia && sdes != NULL) { // SDES stream available, let SDES protect if necessary
rc = sdes->outgoingRtp(buffer, length, newLength);
sdesProtect++;
Expand Down Expand Up @@ -303,7 +298,7 @@ int32_t CtZrtpStream::processIncomingRtp(uint8_t *buffer, const size_t length, s
useLength = newLength + CRC_SIZE; // length check assumes a ZRTP CRC
}
else {
DEBUG(char tmpBuffer[500];)
T_DEBUG(char tmpBuffer[500];)
useZrtpTunnel = false;
// Get CRC value into crc (see above how to compute the offset)
uint16_t temp = length - CRC_SIZE;
Expand All @@ -312,7 +307,7 @@ int32_t CtZrtpStream::processIncomingRtp(uint8_t *buffer, const size_t length, s
if (!zrtpCheckCksum(buffer, temp, crc)) {
zrtpCrcErrors++;
if (zrtpCrcErrors > 15) {
DEBUG(snprintf(debBuf, 499, "len: %d, sdes: %p, sdesMedia: %d, zrtpEncap: %d", temp, (void*)sdes, useSdesForMedia, zrtpEncapSignaled); zrtp_log("CtZrtpStream", debBuf);)
T_DEBUG(snprintf(debBuf, 499, "len: %d, sdes: %p, sdesMedia: %d, zrtpEncap: %d", temp, (void*)sdes, useSdesForMedia, zrtpEncapSignaled); zrtp_log("CtZrtpStream", debBuf);)

sendInfo(Warning, WarningCRCmismatch);
zrtpCrcErrors = 0;
Expand Down Expand Up @@ -341,7 +336,7 @@ int CtZrtpStream::getSignalingHelloHash(char *hHash, int32_t index) {
std::string hash;
hash = zrtpEngine->getHelloHash(index);
strcpy(hHash, hash.c_str());
return hash.size();
return (int)hash.size();
}

void CtZrtpStream::setSignalingHelloHash(const char *hHash) {
Expand Down Expand Up @@ -415,11 +410,11 @@ int CtZrtpStream::isSecure() {
#if __WORDSIZE == 64
#define T_ZRTP_L(_K,_I) \
if(iLen+1 == sizeof(_K) && strncmp(key,_K, iLen) == 0){ \
return snprintf(p, maxLen, "%ld", _I);}
return snprintf(p, maxLen, "%ld", (long)_I);}
#else
#define T_ZRTP_L(_K,_I) \
if(iLen+1 == sizeof(_K) && strncmp(key,_K, iLen) == 0){ \
return snprintf(p, maxLen, "%lld", _I);}
return snprintf(p, maxLen, "%lld", (long long)_I);}
#endif

int CtZrtpStream::getInfo(const char *key, char *p, int maxLen) {
Expand All @@ -431,7 +426,7 @@ int CtZrtpStream::getInfo(const char *key, char *p, int maxLen) {
const ZRtp::zrtpInfo *info = NULL;
ZRtp::zrtpInfo tmpInfo;

int iLen = strlen(key);
int iLen = (int)strlen(key);

// set the security state as a combination of tivi state and stateflags
int secState = tiviState & 0xff;
Expand Down
4 changes: 2 additions & 2 deletions clients/tivi/TiviTimeoutProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ class TimeoutProvider : public CThread {
do {
synchLock.Lock();
int32_t time = 3600000;
int32_t size = 0;
int32_t size = (int32_t)requests.size();

if ((size = requests.size()) > 0) {
if (size > 0) {
time = requests.front()->getMsToTimeout();
}
if (time == 0 && size > 0) {
Expand Down
6 changes: 3 additions & 3 deletions common/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ _THKERNEL( LPVOID lpvData /* CThread Object */
} */

if( pThread->m_type == ThreadTypeIntervalDriven )
Sleep(pThread->m_dwIdle);
Sleep((unsigned int)pThread->m_dwIdle);

}

Expand Down Expand Up @@ -717,7 +717,7 @@ CThread::Pop()
{

m_mutex.Lock();
if( m_queuePos-1 < 0 )
if( (int)m_queuePos-1 < 0 )
{
m_queuePos = 0;
m_dwObjectCondition |= STACK_EMPTY;
Expand Down Expand Up @@ -1071,7 +1071,7 @@ CThread::PingThread(DWORD dwTimeout /* timeout in milli-seconds */
}
dwTotal += m_dwIdle;
m_mutex.Unlock();
Sleep(m_dwIdle);
Sleep((unsigned int)m_dwIdle);
}

return FALSE;
Expand Down
4 changes: 2 additions & 2 deletions srtp/CryptoContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ bool CryptoContext::checkReplay(uint16_t newSeq)
}

delta = -delta;
int idx = delta / 64;
int idx = (int)(delta / 64);
uint64_t bit = 1UL << (delta % 64);
if ((replay_window[idx] & bit) == bit) {
return false; /* Packet already received ! */
Expand Down Expand Up @@ -447,7 +447,7 @@ void CryptoContext::update(uint16_t newSeq)
}
else {
delta = -delta;
int idx = delta / 64;
int idx = (int)(delta / 64);
uint64_t bit = 1UL << (delta % 64);
replay_window[idx] |= bit;
}
Expand Down
16 changes: 8 additions & 8 deletions srtp/SrtpHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool SrtpHandler::protect(CryptoContext* pcc, uint8_t* buffer, size_t length, si
if (pcc == NULL) {
return false;
}
if (!decodeRtp(buffer, length, &ssrc, &seqnum, &payload, &payloadlen))
if (!decodeRtp(buffer, (int32_t)length, &ssrc, &seqnum, &payload, &payloadlen))
return false;

/* Encrypt the packet */
Expand All @@ -107,7 +107,7 @@ bool SrtpHandler::protect(CryptoContext* pcc, uint8_t* buffer, size_t length, si

/* Compute MAC and store at end of RTP packet data */
if (pcc->getTagLength() > 0) {
pcc->srtpAuthenticate(buffer, length, pcc->getRoc(), buffer+length);
pcc->srtpAuthenticate(buffer, (int32_t)length, pcc->getRoc(), buffer+length);
}
*newLength = length + pcc->getTagLength();

Expand All @@ -129,7 +129,7 @@ int32_t SrtpHandler::unprotect(CryptoContext* pcc, uint8_t* buffer, size_t lengt
return 0;
}

if (!decodeRtp(buffer, length, &ssrc, &seqnum, &payload, &payloadlen))
if (!decodeRtp(buffer, (int32_t)length, &ssrc, &seqnum, &payload, &payloadlen))
return 0;
/*
* This is the setting of the packet data when we come to this point:
Expand All @@ -142,7 +142,7 @@ int32_t SrtpHandler::unprotect(CryptoContext* pcc, uint8_t* buffer, size_t lengt
* The SRTP MKI and authentication data is always at the end of a
* packet. Thus compute the position of this data.
*/
uint32_t srtpDataIndex = length - (pcc->getTagLength() + pcc->getMkiLength());
uint32_t srtpDataIndex = (uint32_t)(length - (pcc->getTagLength() + pcc->getMkiLength()));

// Compute new length
length -= pcc->getTagLength() + pcc->getMkiLength();
Expand All @@ -163,7 +163,7 @@ int32_t SrtpHandler::unprotect(CryptoContext* pcc, uint8_t* buffer, size_t lengt
uint64_t guessedIndex = pcc->guessIndex(seqnum);

if (pcc->getTagLength() > 0) {
uint32_t guessedRoc = guessedIndex >> 16;
uint32_t guessedRoc = (uint32_t)(guessedIndex >> 16);
uint8_t mac[20];

pcc->srtpAuthenticate(buffer, (uint32_t)length, guessedRoc, mac);
Expand Down Expand Up @@ -192,7 +192,7 @@ bool SrtpHandler::protectCtrl(CryptoContextCtrl* pcc, uint8_t* buffer, size_t le
ssrc = zrtpNtohl(ssrc);

uint32_t encIndex = pcc->getSrtcpIndex();
pcc->srtcpEncrypt(buffer + 8, length - 8, encIndex, ssrc);
pcc->srtcpEncrypt(buffer + 8, (int32_t)length - 8, encIndex, ssrc);

encIndex |= 0x80000000; // set the E flag

Expand All @@ -204,7 +204,7 @@ bool SrtpHandler::protectCtrl(CryptoContextCtrl* pcc, uint8_t* buffer, size_t le
// take MKI length into account when storing the authentication tag.

// Compute MAC and store in packet after the SRTCP index field
pcc->srtcpAuthenticate(buffer, length, encIndex, buffer + length + sizeof(uint32_t));
pcc->srtcpAuthenticate(buffer, (int32_t)length, encIndex, buffer + length + sizeof(uint32_t));

encIndex++;
encIndex &= ~0x80000000; // clear the E-flag and modulo 2^31
Expand All @@ -222,7 +222,7 @@ int32_t SrtpHandler::unprotectCtrl(CryptoContextCtrl* pcc, uint8_t* buffer, size
}

// Compute the total length of the payload
int32_t payloadLen = length - (pcc->getTagLength() + pcc->getMkiLength() + 4);
int32_t payloadLen = (int32_t)length - (pcc->getTagLength() + pcc->getMkiLength() + 4);
*newLength = payloadLen;

// point to the SRTCP index field just after the real payload
Expand Down
10 changes: 5 additions & 5 deletions zrtp/Base32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void Base32::b2a_l(const unsigned char* os, int len,
/* index into the result buffer, initially pointing to the
* "one-past-the-end" quintet
*/
int resp = result.size();
int resp = (int)result.size();

/* pointer into the os buffer, initially pointing to the
* "one-past-the-end" octet
Expand Down Expand Up @@ -170,14 +170,14 @@ void Base32::b2a_l(const unsigned char* os, int len,
} /* switch ((osp - os.buf) % 5) */

/* truncate any unused trailing zero quintets */
encoded = result.substr(0, divceil(lengthinbits, 5));
encoded = result.substr(0, divceil((int)lengthinbits, 5));
return;
}

void Base32::a2b_l(const string cs, size_t size, const size_t lengthinbits ) {
unsigned long x = 0; // to hold up to 32 bits worth of the input

int len = divceil(size*5, 8);
int len = divceil((int)size*5, 8);

/* if lengthinbits is not a multiple of 5 then this is
* allocating space for 0 or 1 extra octets that will be
Expand All @@ -200,7 +200,7 @@ void Base32::a2b_l(const string cs, size_t size, const size_t lengthinbits ) {
/* index into the input buffer, initially pointing to the
* "one-past-the-end" character
*/
int csp = size;
int csp = (int)size;

/* Now this is a real live Duff's device. You gotta love it. */
switch (csp % 8) {
Expand Down Expand Up @@ -234,7 +234,7 @@ void Base32::a2b_l(const string cs, size_t size, const size_t lengthinbits ) {
} /* switch ((csp - cs.buf) % 8) */

/* truncate any unused trailing zero octets */
resultLength = divceil(lengthinbits, 8);
resultLength = divceil((int)lengthinbits, 8);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions zrtp/ZIDCacheDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int32_t ZIDCacheDb::getPeerName(const uint8_t *peerZid, std::string *name) {
return 0;
}
name->assign(buffer);
return name->length();
return (int32_t)name->length();
}

void ZIDCacheDb::putPeerName(const uint8_t *peerZid, const std::string name) {
Expand All @@ -120,7 +120,7 @@ void ZIDCacheDb::putPeerName(const uint8_t *peerZid, const std::string name) {
cacheOps.readZidNameRecord(zidFile, peerZid, associatedZid, NULL, &nameRec, errorBuffer);

nameRec.name = (char*)name.c_str();
nameRec.nameLength = name.length();
nameRec.nameLength = (int32_t)name.length();
nameRec.nameLength = nameRec.nameLength > 200 ? 200 : nameRec.nameLength;
if ((nameRec.flags & Valid) != Valid) {
nameRec.flags = Valid;
Expand Down
4 changes: 2 additions & 2 deletions zrtp/ZIDRecordDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool ZIDRecordDb::isRs1NotExpired() {
time_t current = time(NULL);
time_t validThru;

validThru = record.rs1Ttl;
validThru = (time_t)record.rs1Ttl;

if (validThru == -1)
return true;
Expand All @@ -65,7 +65,7 @@ bool ZIDRecordDb::isRs2NotExpired() {
time_t current = time(NULL);
time_t validThru;

validThru = record.rs2Ttl;
validThru = (time_t)record.rs2Ttl;

if (validThru == -1)
return true;
Expand Down
4 changes: 2 additions & 2 deletions zrtp/ZIDRecordFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool ZIDRecordFile::isRs1NotExpired() {
if (sizeof(time_t) == 4) {
long long temp;
memcpy((unsigned char*)&temp, record.rs1Interval, TIME_LENGTH);
validThru = temp;
validThru = (time_t)temp;
}
else {
memcpy((unsigned char*)&validThru, record.rs1Interval, TIME_LENGTH);
Expand All @@ -82,7 +82,7 @@ bool ZIDRecordFile::isRs2NotExpired() {
if (sizeof(time_t) == 4) {
long long temp;
memcpy((unsigned char*)&temp, record.rs2Interval, TIME_LENGTH);
validThru = temp;
validThru = (time_t)temp;
}
else {
memcpy((unsigned char*)&validThru, record.rs2Interval, TIME_LENGTH);
Expand Down
Loading