Merge pull request #5857 from Icinga/fix/compiler-warnings

Fix compiler warnings
This commit is contained in:
Gunnar Beutner 2017-12-14 13:49:25 +01:00 committed by GitHub
commit 1bf12c9685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 326 additions and 302 deletions

View File

@ -7,14 +7,17 @@ using System.Text;
namespace Icinga
{
static class Program
internal static class NativeMethods
{
[DllImport("msi.dll", SetLastError = true)]
static extern int MsiEnumProducts(int iProductIndex, StringBuilder lpProductBuf);
[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);
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();
}

View File

@ -106,7 +106,7 @@ static int Main(void)
try {
autoindex = Convert::ToLong(argv[2]);
} catch (const std::invalid_argument& ex) {
} catch (const std::invalid_argument&) {
Log(LogCritical, "icinga-app")
<< "Invalid index for --autocomplete: " << argv[2];
return EXIT_FAILURE;
@ -684,14 +684,15 @@ static int SetupService(bool install, int argc, char **argv)
return 1;
}
printf("Service successfully installed for user '%s'\n", scmUser);
std::cout << "Service successfully installed for user '" << scmUser << "'\n";
std::ofstream fuser(Utility::GetIcingaDataPath() + "\\etc\\icinga2\\user", std::ios::out | std::ios::trunc);
String userFilePath = Utility::GetIcingaDataPath() + "\\etc\\icinga2\\user";
std::ofstream fuser(userFilePath.CStr(), std::ios::out | std::ios::trunc);
if (fuser)
fuser << scmUser;
else
printf("Could not write user to %s\\etc\\icinga2\\user", Utility::GetIcingaDataPath());
fuser.close();
std::cout << "Could not write user to " << userFilePath << "\n";
}
CloseServiceHandle(schService);

View 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

View 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;

View File

@ -25,15 +25,20 @@
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)); \
} }
}

View 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) << "\"";
BOOST_THROW_EXCEPTION(socket_error()
<< 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()) << "\"";
BOOST_THROW_EXCEPTION(socket_error()
<< boost::errinfo_api_function("accept")
<< errinfo_win32_error(WSAGetLastError()));
#endif /* _WIN32 */
}
#endif /* _WIN32 */
return new Socket(fd);
}

View 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);

View File

@ -1780,7 +1780,7 @@ String Utility::CreateTempFile(const String& path, int mode, std::fstream& fp)
try {
fp.open(&targetPath[0], std::ios_base::trunc | std::ios_base::out);
} catch (const std::fstream::failure& e) {
} catch (const std::fstream::failure&) {
close(fd);
throw;
}

View 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 */

View 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);

View 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);

View File

@ -515,7 +515,7 @@ void ConsoleCommand::ExecuteScriptCompletionHandler(boost::mutex& mutex, boost::
if (eptr) {
try {
boost::rethrow_exception(eptr);
} catch (const ScriptError& ex) {
} catch (const ScriptError&) {
eptrOut = boost::current_exception();
} catch (const std::exception& ex) {
Log(LogCritical, "ConsoleCommand")

View File

@ -948,7 +948,7 @@ ExpressionResult TryExceptExpression::DoEvaluate(ScriptFrame& frame, DebugHint *
try {
ExpressionResult tryResult = m_TryBody->Evaluate(frame, dhint);
CHECK_RESULT(tryResult);
} catch (const std::exception& ex) {
} catch (const std::exception&) {
ExpressionResult exceptResult = m_ExceptBody->Evaluate(frame, dhint);
CHECK_RESULT(exceptResult);
}

View File

@ -48,7 +48,7 @@ void ApiClient::GetTypes(const TypesCompletionCallback& callback) const
req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password));
req->AddHeader("Accept", "application/json");
m_Connection->SubmitRequest(req, std::bind(TypesHttpCompletionCallback, _1, _2, callback));
} catch (const std::exception& ex) {
} catch (const std::exception&) {
callback(boost::current_exception(), std::vector<ApiType::Ptr>());
}
}
@ -133,7 +133,7 @@ void ApiClient::GetObjects(const String& pluralType, const ObjectsCompletionCall
req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password));
req->AddHeader("Accept", "application/json");
m_Connection->SubmitRequest(req, std::bind(ObjectsHttpCompletionCallback, _1, _2, callback));
} catch (const std::exception& ex) {
} catch (const std::exception&) {
callback(boost::current_exception(), std::vector<ApiObject::Ptr>());
}
}
@ -242,7 +242,7 @@ void ApiClient::ExecuteScript(const String& session, const String& command, bool
req->AddHeader("Authorization", "Basic " + Base64::Encode(m_User + ":" + m_Password));
req->AddHeader("Accept", "application/json");
m_Connection->SubmitRequest(req, std::bind(ExecuteScriptHttpCompletionCallback, _1, _2, callback));
} catch (const std::exception& ex) {
} catch (const std::exception&) {
callback(boost::current_exception(), Empty);
}
}
@ -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);
}
}

View File

@ -449,7 +449,7 @@ void ApiListener::NewClientHandlerInternal(const Socket::Ptr& client, const Stri
try {
tlsStream->Handshake();
} catch (const std::exception& ex) {
} catch (const std::exception&) {
Log(LogCritical, "ApiListener")
<< "Client TLS handshake failed (" << conninfo << ")";
return;

View File

@ -271,7 +271,7 @@ std::vector<Value> FilterUtility::GetFilterTargets(const QueryDescription& qd, c
provider->FindTargets(type, std::bind(&FilteredAddTarget,
std::ref(permissionFrame), permissionFilter,
std::ref(frame), ufilter, std::ref(result), variableName, _1));
} catch (const std::exception& ex) {
} catch (const std::exception&) {
delete ufilter;
throw;
}

View File

@ -115,7 +115,7 @@ bool HttpClientConnection::ProcessMessage(void)
try {
res = response.Parse(m_Context, false);
} catch (const std::exception& ex) {
} catch (const std::exception&) {
callback(request, response);
m_Stream->Shutdown();

View 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;
}

View 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);

View 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;

View File

@ -146,7 +146,7 @@ static int FormatOutput(const Dictionary::Ptr& result)
Dictionary::Ptr payload;
try {
payload = payloads->Get(0);
} catch (const std::exception& ex) {
} catch (const std::exception&) {
std::cout << "UNKNOWN: Answer format error: 'payload' was not a Dictionary.\n";
return 3;
}
@ -171,7 +171,7 @@ static int FormatOutput(const Dictionary::Ptr& result)
Dictionary::Ptr line;
try {
line = vline;
} catch (const std::exception& ex) {
} catch (const std::exception&) {
std::cout << "UNKNOWN: Answer format error: 'lines' entry was not a Dictionary.\n";
return 3;
}

View File

@ -119,9 +119,9 @@ INT parseArguments(INT ac, WCHAR **av, po::variables_map& vm, printInfoStruct& p
wprintf(
L"\nIt will take at least timeout times number of pings to run\n"
L"Then it will output a string looking something like this:\n\n"
L"\tPING WARNING RTA: 72ms Packet loss: 20% | ping=72ms;40;80;71;77 pl=20%;20;50;0;100\n\n"
L"\tPING WARNING RTA: 72ms Packet loss: 20%% | ping=72ms;40;80;71;77 pl=20%%;20;50;0;100\n\n"
L"\"PING\" being the type of the check, \"WARNING\" the returned status\n"
L"and \"RTA: 72ms Packet loss: 20%\" the relevant information.\n"
L"and \"RTA: 72ms Packet loss: 20%%\" the relevant information.\n"
L"The performance data is found behind the \"|\", in order:\n"
L"returned value, warning threshold, critical threshold, minimal value and,\n"
L"if applicable, the maximal value. \n\n"
@ -145,8 +145,8 @@ INT parseArguments(INT ac, WCHAR **av, po::variables_map& vm, printInfoStruct& p
L"Does nothing if the plugin does not accept percentages, or only uses\n"
L"percentage thresholds. Ranges can be used with \"%%\", but both range values need\n"
L"to end with a percentage sign.\n\n"
L"All of these options work with the critical threshold \"-c\" too."
, progName);
L"All of these options work with the critical threshold \"-c\" too.",
progName);
std::cout << '\n';
return 0;
}

View File

@ -253,7 +253,7 @@ DWORD ServiceStatus(CONST printInfoStruct& printInfo)
{
SC_HANDLE hSCM;
SC_HANDLE hService;
DWORD cbBufSize, lpServicesReturned, pcbBytesNeeded;
DWORD cbBufSize;
DWORD lpResumeHandle = 0;
LPBYTE lpBuf = NULL;

View 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) {

View File

@ -355,7 +355,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
m_Impl << "\t" << "int real_id = id - " << klass.Parent << "::TypeInstance->GetFieldCount();" << std::endl
<< "\t" << "if (real_id < 0) { return " << klass.Parent << "::TypeInstance->GetFieldInfo(id); }" << std::endl;
if (klass.Fields.size() > 0) {
if (!klass.Fields.empty()) {
m_Impl << "\t" << "switch (";
if (!klass.Parent.empty())
@ -387,7 +387,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
m_Impl << "\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl;
if (klass.Fields.size() > 0)
if (!klass.Fields.empty())
m_Impl << "\t" << "}" << std::endl;
m_Impl << "}" << std::endl << std::endl;
@ -437,6 +437,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
m_Impl << "\t" << "int real_id = fieldId - " << klass.Parent << "::TypeInstance->GetFieldCount(); " << std::endl
<< "\t" << "if (real_id < 0) { " << klass.Parent << "::TypeInstance->RegisterAttributeHandler(fieldId, callback); return; }" << std::endl;
if (!klass.Fields.empty()) {
m_Impl << "\t" << "switch (";
if (!klass.Parent.empty())
@ -455,8 +456,12 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
}
m_Impl << "\t\t" << "default:" << std::endl
<< "\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl
<< "\t" << "}" << std::endl;
<< "\t\t";
}
m_Impl << "\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl;
if (!klass.Fields.empty())
m_Impl << "\t" << "}" << std::endl;
m_Impl << "}" << std::endl << std::endl;
@ -749,6 +754,16 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
m_Impl << "\t" << "int real_id = id - " << klass.Parent << "::TypeInstance->GetFieldCount(); " << std::endl
<< "\t" << "if (real_id < 0) { return " << klass.Parent << "::NavigateField(id); }" << std::endl;
bool haveNavigationFields = false;
for (const Field& field : klass.Fields) {
if (field.Attributes & FANavigation) {
haveNavigationFields = true;
break;
}
}
if (haveNavigationFields) {
m_Impl << "\t" << "switch (";
if (!klass.Parent.empty())
@ -769,8 +784,13 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
}
m_Impl << "\t\t" << "default:" << std::endl
<< "\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl
<< "\t" << "}" << std::endl;
<< "\t\t";
}
m_Impl << "\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl;
if (haveNavigationFields)
m_Impl << "\t" << "}" << std::endl;
m_Impl << "}" << std::endl << std::endl;