]> jfr.im git - irc/rizon/znc.git/commitdiff
Fix more warnings and #197
authorAlexey Sokolov <redacted>
Thu, 16 Aug 2012 17:56:53 +0000 (00:56 +0700)
committerAlexey Sokolov <redacted>
Thu, 16 Aug 2012 18:16:34 +0000 (01:16 +0700)
modules/dcc.cpp
modules/q.cpp
modules/sasl.cpp
src/FileUtils.cpp
src/main.cpp
src/znc.cpp

index 9780d3e3f7ec03c1978fd70d1d1db83543a0b038..e20f49a887cce514791b68903b398057599ccd1a 100644 (file)
@@ -31,7 +31,7 @@ public:
        void SendPacket();
        virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort);
        CFile* OpenFile(bool bWrite = true);
-       bool Seek(unsigned int uPos);
+       bool Seek(unsigned long int uPos);
 
        // Setters
        void SetRemoteIP(const CString& s) { m_sRemoteIP = s; }
@@ -58,8 +58,8 @@ protected:
        CString         m_sLocalFile;
        CString         m_sSendBuf;
        unsigned short  m_uRemotePort;
-       unsigned long   m_uFileSize;
-       unsigned long   m_uBytesSoFar;
+       unsigned long long  m_uFileSize;
+       unsigned long long  m_uBytesSoFar;
        bool            m_bSend;
        bool            m_bNoDelFile;
        CFile*          m_pFile;
@@ -309,7 +309,7 @@ void CDCCSock::ReadData(const char* data, size_t len) {
        } else {
                m_pFile->Write(data, len);
                m_uBytesSoFar += len;
-               uint32_t uSoFar = htonl(m_uBytesSoFar);
+               uint32_t uSoFar = htonl((uint32_t)m_uBytesSoFar);
                Write((char*) &uSoFar, sizeof(uSoFar));
 
                if (m_uBytesSoFar >= m_uFileSize) {
@@ -447,14 +447,14 @@ CFile* CDCCSock::OpenFile(bool bWrite) {
                // The DCC specs only allow file transfers with files smaller
                // than 4GiB (see ReadData()).
                unsigned long long uFileSize = m_pFile->GetSize();
-               if (uFileSize > (unsigned long long) 0xffffffff) {
+               if (uFileSize > (unsigned long long) 0xffffffffULL) {
                        delete m_pFile;
                        m_pFile = NULL;
                        m_pModule->PutModule("DCC -> [" + m_sRemoteNick + "] - File too large (>4 GiB) [" + m_sLocalFile + "]");
                        return NULL;
                }
 
-               m_uFileSize = (unsigned long) uFileSize;
+               m_uFileSize = uFileSize;
        }
 
        m_sFileName = m_pFile->GetShortName();
@@ -462,7 +462,7 @@ CFile* CDCCSock::OpenFile(bool bWrite) {
        return m_pFile;
 }
 
-bool CDCCSock::Seek(unsigned int uPos) {
+bool CDCCSock::Seek(unsigned long int uPos) {
        if (m_pFile) {
                if (m_pFile->Seek(uPos)) {
                        m_uBytesSoFar = uPos;
index 6a7e39e775c781c1a2406c92c2b51229dd88eaf0..ac6a228a38901ac977ddd8dd63bb6688342cca92 100644 (file)
@@ -443,7 +443,7 @@ private:
                CString sOuterKey, sInnerKey;
                CString::size_type iKeyLength = sRealKey.length();
                for (unsigned int i = 0; i < 64; i++) {
-                       int r = (i < iKeyLength ? sRealKey[i] : 0);
+                       char r = (i < iKeyLength ? sRealKey[i] : '\0');
                        sOuterKey += r ^ 0x5c;
                        sInnerKey += r ^ 0x36;
                }
index 890374c3466046ebeecd9b685f1b8d1023ffc38d..8eb5f665c6eeb19e7b0725c22a374cb834b91ac3 100644 (file)
@@ -222,8 +222,7 @@ public:
                }
 
                /* Prime number */
-               unsigned int size = ntohs((((unsigned int)data[1]) << 8) | data[0]);
-               size = ntohs(*(unsigned int*)data);
+               unsigned int size = ntohs(*(uint16_t*)data);
                data += 2;
                length -= 2;
 
@@ -243,8 +242,7 @@ public:
                        return false;
                }
 
-               size = ntohs((((unsigned int)data[1]) << 8) | data[0]);
-               size = ntohs(*(unsigned int*)data);
+               size = ntohs(*(uint16_t*)data);
                data += 2;
                length -= 2;
 
@@ -258,8 +256,7 @@ public:
                data += size;
 
                /* Server public key */
-               size = ntohs((((unsigned int)data[1]) << 8) | data[0]);
-               size = ntohs(*(unsigned int*)data);
+               size = ntohs(*(uint16_t*)data);
                data += 2;
                length -= 2;
 
@@ -289,6 +286,7 @@ public:
                }
 
                /* Encrypt our sasl password with blowfish */
+               // TODO for passwords with length 8, 16, 24, 32, etc. this will have 8 additional zero bytes at the end... But it works when treated as null-terminated string anyway, and if it works I don't want to touch it right now.
                CString::size_type password_length = GetNV("password").size() + (8 - (GetNV("password").size() % 8));
                unsigned char *encrypted_password = (unsigned char *)malloc(password_length);
                char *plaintext_password = (char *)malloc(password_length);
@@ -315,7 +313,7 @@ public:
                out_ptr = response;
 
                /* Add our key to the response */
-               *((unsigned int *)out_ptr) = htons(BN_num_bytes(dh->pub_key));
+               *((uint16_t *)out_ptr) = htons((uint16_t)BN_num_bytes(dh->pub_key));
                out_ptr += 2;
                BN_bn2bin(dh->pub_key, (unsigned char *)out_ptr);
                out_ptr += BN_num_bytes(dh->pub_key);
index e15bd11657f3d1e0fc2ec0f6a316fc8e3e1cd75c..1aba0c99c585bae673f99c76e4fa698df52b9e72 100644 (file)
@@ -412,7 +412,7 @@ ssize_t CFile::Write(const char *pszBuffer, size_t iBytes) {
        }
 
        ssize_t res = write(m_iFD, pszBuffer, iBytes);
-       if (res != iBytes)
+       if (-1 == res)
                m_bHadError = true;
        return res;
 }
index dcff4852d42931b0122314a9b939c387662e59d6..10491efb541e1620726db2f5bfd4fb297d7a2778 100644 (file)
@@ -108,7 +108,7 @@ static void seedPRNG() {
 
                // This is in [0:1e6], which means that roughly 20 bits are
                // actually used, let's try to shuffle the high bits.
-               seed ^= (tv.tv_usec << 10) | tv.tv_usec;
+               seed ^= uint32_t((tv.tv_usec << 10) | tv.tv_usec);
        } else
                seed = (unsigned int)time(NULL);
 
index e3fcefe8dd588e5ddc87c9634e0a7edb3071976c..a3ea2fbcf3e3aa39f8411068ba922de6f3430ff0 100644 (file)
@@ -582,7 +582,7 @@ bool CZNC::WriteNewConfig(const CString& sConfigFile) {
                CUtils::GetInput("Listen Host", sListenHost, sListenHost, "Blank for all ips");
 
                CUtils::PrintAction("Verifying the listener");
-               CListener* pListener = new CListener(uListenPort, sListenHost, bListenSSL,
+               CListener* pListener = new CListener((unsigned short int)uListenPort, sListenHost, bListenSSL,
                                b6 ? ADDR_ALL : ADDR_IPV4ONLY, CListener::ACCEPT_ALL);
                if (!pListener->Listen()) {
                        CUtils::PrintStatus(false, FormatBindError());