]> granicus.if.org Git - icinga2/commitdiff
Fix compiler warnings 5857/head
authorGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 14 Dec 2017 07:47:04 +0000 (08:47 +0100)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 14 Dec 2017 08:15:37 +0000 (09:15 +0100)
14 files changed:
agent/windows-setup-agent/Program.cs
lib/base/array.cpp
lib/base/array.hpp
lib/base/initialize.hpp
lib/base/socket.cpp
lib/base/tcpsocket.cpp
lib/base/visibility.hpp
lib/base/workqueue.cpp
lib/base/workqueue.hpp
lib/remote/apiclient.cpp
lib/remote/jsonrpcconnection.cpp
lib/remote/jsonrpcconnection.hpp
plugins/check_disk.cpp
plugins/thresholds.cpp

index 4b85731f1fafc76b264775ca61a739639ce8c4a1..b22b042eb70e077df81744489982638ec4a3e44b 100644 (file)
@@ -7,14 +7,17 @@ using System.Text;
 
 namespace Icinga
 {
-       static class Program
-       {
-               [DllImport("msi.dll", SetLastError = true)]
-               static extern int MsiEnumProducts(int iProductIndex, StringBuilder lpProductBuf);
+    internal static class NativeMethods
+    {
+        [DllImport("msi.dll", CharSet = CharSet.Unicode)]
+        internal static extern int MsiEnumProducts(int iProductIndex, StringBuilder lpProductBuf);
 
-               [DllImport("msi.dll", CharSet = CharSet.Unicode)]
-               static extern Int32 MsiGetProductInfo(string product, string property, [Out] StringBuilder valueBuf, ref Int32 len);
+        [DllImport("msi.dll", CharSet = CharSet.Unicode)]
+        internal static extern Int32 MsiGetProductInfo(string product, string property, [Out] StringBuilder valueBuf, ref Int32 len);
+    }
 
+    static class Program
+       {
                public static string Icinga2InstallDir
                {
                        get
@@ -23,13 +26,13 @@ namespace Icinga
 
                                for (int index = 0; ; index++) {
                                        szProduct = new StringBuilder(39);
-                                       if (MsiEnumProducts(index, szProduct) != 0)
+                                       if (NativeMethods.MsiEnumProducts(index, szProduct) != 0)
                                                break;
 
                                        int cbName = 128;
                                        StringBuilder szName = new StringBuilder(cbName);
 
-                                       if (MsiGetProductInfo(szProduct.ToString(), "ProductName", szName, ref cbName) != 0)
+                                       if (NativeMethods.MsiGetProductInfo(szProduct.ToString(), "ProductName", szName, ref cbName) != 0)
                                                continue;
 
                                        if (szName.ToString() != "Icinga 2")
@@ -37,7 +40,7 @@ namespace Icinga
 
                                        int cbLocation = 1024;
                                        StringBuilder szLocation = new StringBuilder(cbLocation);
-                                       if (MsiGetProductInfo(szProduct.ToString(), "InstallLocation", szLocation, ref cbLocation) == 0)
+                                       if (NativeMethods.MsiGetProductInfo(szProduct.ToString(), "InstallLocation", szLocation, ref cbLocation) == 0)
                                                return szLocation.ToString();
                                }
 
index 21dcc7613d2f21a710b0e0619cc340b775e08907..32d97a4fdd4a801b5597ffbe634cef3b6b550e3c 100644 (file)
@@ -36,7 +36,7 @@ REGISTER_PRIMITIVE_TYPE(Array, Object, Array::GetPrototype());
  * @param index The index.
  * @returns The value.
  */
-Value Array::Get(unsigned int index) const
+Value Array::Get(SizeType index) const
 {
        ObjectLock olock(this);
 
@@ -49,7 +49,7 @@ Value Array::Get(unsigned int index) const
  * @param index The index.
  * @param value The value.
  */
-void Array::Set(unsigned int index, const Value& value)
+void Array::Set(SizeType index, const Value& value)
 {
        ObjectLock olock(this);
 
@@ -62,7 +62,7 @@ void Array::Set(unsigned int index, const Value& value)
  * @param index The index.
  * @param value The value.
  */
-void Array::Set(unsigned int index, Value&& value)
+void Array::Set(SizeType index, Value&& value)
 {
        ObjectLock olock(this);
 
@@ -124,7 +124,7 @@ bool Array::Contains(const Value& value) const
  * @param index The index
  * @param value The value to add
  */
-void Array::Insert(unsigned int index, const Value& value)
+void Array::Insert(SizeType index, const Value& value)
 {
        ObjectLock olock(this);
 
@@ -138,7 +138,7 @@ void Array::Insert(unsigned int index, const Value& value)
  *
  * @param index The index.
  */
-void Array::Remove(unsigned int index)
+void Array::Remove(SizeType index)
 {
        ObjectLock olock(this);
 
@@ -157,11 +157,11 @@ void Array::Remove(Array::Iterator it)
        m_Data.erase(it);
 }
 
-void Array::Resize(size_t new_size)
+void Array::Resize(SizeType newSize)
 {
        ObjectLock olock(this);
 
-       m_Data.resize(new_size);
+       m_Data.resize(newSize);
 }
 
 void Array::Clear(void)
@@ -171,11 +171,11 @@ void Array::Clear(void)
        m_Data.clear();
 }
 
-void Array::Reserve(size_t new_size)
+void Array::Reserve(SizeType newSize)
 {
        ObjectLock olock(this);
 
-       m_Data.reserve(new_size);
+       m_Data.reserve(newSize);
 }
 
 void Array::CopyTo(const Array::Ptr& dest) const
index 7abb86e6365a3b21bd8cff42e799033c58609311..682fdfe81b7db34015dac92739a919567fcb7df3 100644 (file)
@@ -57,9 +57,9 @@ public:
        inline ~Array(void)
        { }
 
-       Value Get(unsigned int index) const;
-       void Set(unsigned int index, const Value& value);
-       void Set(unsigned int index, Value&& value);
+       Value Get(SizeType index) const;
+       void Set(SizeType index, const Value& value);
+       void Set(SizeType index, Value&& value);
        void Add(const Value& value);
        void Add(Value&& value);
 
@@ -94,14 +94,14 @@ public:
        size_t GetLength(void) const;
        bool Contains(const Value& value) const;
 
-       void Insert(unsigned int index, const Value& value);
-       void Remove(unsigned int index);
+       void Insert(SizeType index, const Value& value);
+       void Remove(SizeType index);
        void Remove(Iterator it);
 
-       void Resize(size_t new_size);
+       void Resize(SizeType newSize);
        void Clear(void);
 
-       void Reserve(size_t new_size);
+       void Reserve(SizeType newSize);
 
        void CopyTo(const Array::Ptr& dest) const;
        Array::Ptr ShallowClone(void) const;
index 92c8e957189fc313a04b519b3328c569ceb44e12..00162ea48ab86a4246eabf318afb90aaad8c194a 100644 (file)
 namespace icinga
 {
 
+#define I2_TOKENPASTE(x, y) x ## y
+#define I2_TOKENPASTE2(x, y) I2_TOKENPASTE(x, y)
+
+#define I2_UNIQUE_NAME(prefix) I2_TOKENPASTE2(prefix, __COUNTER__)
+
 I2_BASE_API bool InitializeOnceHelper(void (*func)(void), int priority = 0);
 
 #define INITIALIZE_ONCE(func)                                                                  \
-       namespace { namespace UNIQUE_NAME(io) {                                                 \
+       namespace { namespace I2_UNIQUE_NAME(io) {                                                      \
                I2_EXPORT bool l_InitializeOnce(icinga::InitializeOnceHelper(func));            \
        } }
 
 #define INITIALIZE_ONCE_WITH_PRIORITY(func, priority)                                          \
-       namespace { namespace UNIQUE_NAME(io) {                                                 \
+       namespace { namespace I2_UNIQUE_NAME(io) {                                                      \
                I2_EXPORT bool l_InitializeOnce(icinga::InitializeOnceHelper(func, priority));  \
        } }
 }
index 026da03c37e613138fde6cdced98dddbc8aac258..b3811196c5e4744c8a8e89e625be968f80783ddd 100644 (file)
@@ -330,29 +330,30 @@ size_t Socket::Read(void *buffer, size_t count)
  */
 Socket::Ptr Socket::Accept(void)
 {
-       int fd;
        sockaddr_storage addr;
        socklen_t addrlen = sizeof(addr);
 
-       fd = accept(GetFD(), (sockaddr *)&addr, &addrlen);
+       SOCKET fd = accept(GetFD(), (sockaddr *)&addr, &addrlen);
 
-       if (fd < 0) {
 #ifndef _WIN32
+       if (fd < 0) {
                Log(LogCritical, "Socket")
-                   << "accept() failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
+                       << "accept() failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
 
                BOOST_THROW_EXCEPTION(socket_error()
-                   << boost::errinfo_api_function("accept")
-                   << boost::errinfo_errno(errno));
+                       << boost::errinfo_api_function("accept")
+                       << boost::errinfo_errno(errno));
+       }
 #else /* _WIN32 */
+       if (fd == INVALID_SOCKET) {
                Log(LogCritical, "Socket")
-                   << "accept() failed with error code " << WSAGetLastError() << ", \"" << Utility::FormatErrorNumber(WSAGetLastError()) << "\"";
+                       << "accept() failed with error code " << WSAGetLastError() << ", \"" << Utility::FormatErrorNumber(WSAGetLastError()) << "\"";
 
                BOOST_THROW_EXCEPTION(socket_error()
-                   << boost::errinfo_api_function("accept")
-                   << errinfo_win32_error(WSAGetLastError()));
-#endif /* _WIN32 */
+                       << boost::errinfo_api_function("accept")
+                       << errinfo_win32_error(WSAGetLastError()));
        }
+#endif /* _WIN32 */
 
        return new Socket(fd);
 }
index 734f0878d90c4b96241f8fbd2e807a11aa513389..113306436d2fa9a79cfa82ad5f43277955b2e885 100644 (file)
@@ -161,7 +161,7 @@ void TcpSocket::Connect(const String& node, const String& service)
                    << errinfo_getaddrinfo_error(rc));
        }
 
-       int fd = INVALID_SOCKET;
+       SOCKET fd = INVALID_SOCKET;
 
        for (addrinfo *info = result; info != NULL; info = info->ai_next) {
                fd = socket(info->ai_family, info->ai_socktype, info->ai_protocol);
index d80dbc4f3b1664db813dc3d8e47c490d4d37c2bb..91f2252e5c2f89302724ec217031342dbe99d9f7 100644 (file)
@@ -29,9 +29,4 @@
 #      define I2_HIDDEN
 #endif /* _WIN32 */
 
-#define TOKENPASTE(x, y) x ## y
-#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
-
-#define UNIQUE_NAME(prefix) TOKENPASTE2(prefix, __COUNTER__)
-
 #endif /* VISIBILITY_H */
index a59acdcadbc70d28901e680f38570e3aa7a60942..c9ee69bed7e9bc8e220853fd09efc88e164ee6c5 100644 (file)
@@ -27,7 +27,7 @@
 
 using namespace icinga;
 
-int WorkQueue::m_NextID = 1;
+std::atomic<int> WorkQueue::m_NextID(1);
 boost::thread_specific_ptr<WorkQueue *> l_ThreadWorkQueue;
 
 WorkQueue::WorkQueue(size_t maxItems, int threadCount)
@@ -196,7 +196,7 @@ void WorkQueue::StatusTimerHandler(void)
 
        ASSERT(!m_Name.IsEmpty());
 
-       int pending = m_Tasks.size();
+       size_t pending = m_Tasks.size();
 
        double now = Utility::GetTime();
        double gradient = (pending - m_PendingTasks) / (now - m_PendingTasksTimestamp);
@@ -295,7 +295,7 @@ void WorkQueue::IncreaseTaskCount(void)
        m_TaskStats.InsertValue(now, 1);
 }
 
-int WorkQueue::GetTaskCount(RingBuffer::SizeType span)
+size_t WorkQueue::GetTaskCount(RingBuffer::SizeType span)
 {
        boost::mutex::scoped_lock lock(m_StatsMutex);
        return m_TaskStats.UpdateAndGetValues(Utility::GetTime(), span);
index c44e117fd26c3332ad8a9b10a92b582d7cb3de48..c88677c02192d688fd3be2964ae32ce005fa6807 100644 (file)
@@ -29,6 +29,7 @@
 #include <boost/exception_ptr.hpp>
 #include <queue>
 #include <deque>
+#include <atomic>
 
 namespace icinga
 {
@@ -93,7 +94,7 @@ public:
        bool IsWorkerThread(void) const;
 
        size_t GetLength(void) const;
-       int GetTaskCount(RingBuffer::SizeType span);
+       size_t GetTaskCount(RingBuffer::SizeType span);
 
        void SetExceptionCallback(const ExceptionCallback& callback);
 
@@ -107,7 +108,7 @@ protected:
 private:
        int m_ID;
        String m_Name;
-       static int m_NextID;
+       static std::atomic<int> m_NextID;
        int m_ThreadCount;
        bool m_Spawned;
 
@@ -128,7 +129,7 @@ private:
 
        mutable boost::mutex m_StatsMutex;
        RingBuffer m_TaskStats;
-       int m_PendingTasks;
+       size_t m_PendingTasks;
        double m_PendingTasksTimestamp;
 
        void WorkerThreadProc(void);
index 8cf41d38fc938ffb6d5962be6e63e16cd39f559e..3638485d9ddbcf44dc8e88cb93c29fb0bcc5ffdd 100644 (file)
@@ -294,7 +294,7 @@ void ApiClient::ExecuteScriptHttpCompletionCallback(HttpRequest& request,
                }
 
                callback(boost::exception_ptr(), result);
-       } catch (const std::exception& ex) {
+       } catch (const std::exception&) {
                callback(boost::current_exception(), Empty);
        }
 }
@@ -321,7 +321,7 @@ void ApiClient::AutocompleteScript(const String& session, const String& command,
                req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password));
                req->AddHeader("Accept", "application/json");
                m_Connection->SubmitRequest(req, std::bind(AutocompleteScriptHttpCompletionCallback, _1, _2, callback));
-       } catch (const std::exception& ex) {
+       } catch (const std::exception&) {
                callback(boost::current_exception(), nullptr);
        }
 }
@@ -362,7 +362,7 @@ void ApiClient::AutocompleteScriptHttpCompletionCallback(HttpRequest& request,
                }
 
                callback(boost::exception_ptr(), suggestions);
-       } catch (const std::exception& ex) {
+       } catch (const std::exception&) {
                callback(boost::current_exception(), nullptr);
        }
 }
index 95be46984e05c24f91302d5c76a96e1f1f74b774..cf397f9a9a301a0b922ec9f45c922432d590e713 100644 (file)
@@ -322,18 +322,17 @@ void JsonRpcConnection::TimeoutTimerHandler(void)
        }
 }
 
-int JsonRpcConnection::GetWorkQueueCount(void)
+size_t JsonRpcConnection::GetWorkQueueCount(void)
 {
        return l_JsonRpcConnectionWorkQueueCount;
 }
 
-int JsonRpcConnection::GetWorkQueueLength(void)
+size_t JsonRpcConnection::GetWorkQueueLength(void)
 {
-       int itemCount = 0;
+       size_t itemCount = 0;
 
-       for (int i = 0; i < GetWorkQueueCount(); i++) {
+       for (size_t i = 0; i < GetWorkQueueCount(); i++)
                itemCount += l_JsonRpcConnectionWorkQueues[i].GetLength();
-       }
 
        return itemCount;
 }
@@ -341,15 +340,14 @@ int JsonRpcConnection::GetWorkQueueLength(void)
 double JsonRpcConnection::GetWorkQueueRate(void)
 {
        double rate = 0.0;
-       int count = GetWorkQueueCount();
+       size_t count = GetWorkQueueCount();
 
        /* If this is a standalone environment, we don't have any queues. */
        if (count == 0)
                return 0.0;
 
-       for (int i = 0; i < count; i++) {
+       for (size_t i = 0; i < count; i++)
                rate += l_JsonRpcConnectionWorkQueues[i].GetTaskCount(60) / 60.0;
-       }
 
        return rate / count;
 }
index e62799c1eca69fafd104b369d7e234ca38950584..d4fce95cd1276e7b895b0e82c97a612f4f6bfea4 100644 (file)
@@ -71,8 +71,8 @@ public:
        static void HeartbeatTimerHandler(void);
        static Value HeartbeatAPIHandler(const intrusive_ptr<MessageOrigin>& origin, const Dictionary::Ptr& params);
 
-       static int GetWorkQueueCount(void);
-       static int GetWorkQueueLength(void);
+       static size_t GetWorkQueueCount(void);
+       static size_t GetWorkQueueLength(void);
        static double GetWorkQueueRate(void);
 
        static void SendCertificateRequest(const JsonRpcConnection::Ptr& aclient, const intrusive_ptr<MessageOrigin>& origin, const String& path);
index 1242368473157ace437d22fa554c64bbd51f19e0..f4866c24cc0ef5c7a88dfa96a43b8820c987ef37 100644 (file)
@@ -186,7 +186,7 @@ static INT parseArguments(INT ac, WCHAR **av, po::variables_map& vm, printInfoSt
                        printInfo.unit = BunitB;
        }
 
-       printInfo.showUsed = vm.count("show-used");
+       printInfo.showUsed = vm.count("show-used") > 0;
 
        if (vm.count("debug"))
                debug = TRUE;
index 29aede81834a83e4f213d8e67f079bf80ff74d29..0d0ffc7825241cf4cb5750abaafc492f5c293ef2 100644 (file)
@@ -129,7 +129,7 @@ std::wstring threshold::pString(CONST DOUBLE max)
 std::wstring removeZero(DOUBLE val)
 {
        std::wstring ret = boost::lexical_cast<std::wstring>(val);
-       INT pos = ret.length();
+       std::wstring::size_type pos = ret.length();
        if (ret.find_first_of(L".") == std::string::npos)
                return ret;
        for (std::wstring::reverse_iterator rit = ret.rbegin(); rit != ret.rend(); ++rit) {