summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-10-06 16:48:16 -0400
committerDavid Robillard <d@drobilla.net>2024-10-06 19:06:42 -0400
commit8448ed74a88312d5cf1ca7862aff8c2087c0ffbc (patch)
tree27063887bcce13f40e61b441440f85035d0b5220
parent76d0f42479d8783f1ed7a5017e841754188d025f (diff)
downloadingen-8448ed74a88312d5cf1ca7862aff8c2087c0ffbc.tar.gz
ingen-8448ed74a88312d5cf1ca7862aff8c2087c0ffbc.tar.bz2
ingen-8448ed74a88312d5cf1ca7862aff8c2087c0ffbc.zip
Avoid using uninitialized va_list variables
-rw-r--r--.suppress.cppcheck1
-rw-r--r--include/ingen/Log.hpp3
-rw-r--r--src/Log.cpp34
3 files changed, 22 insertions, 16 deletions
diff --git a/.suppress.cppcheck b/.suppress.cppcheck
index bad404e6..44f9e760 100644
--- a/.suppress.cppcheck
+++ b/.suppress.cppcheck
@@ -18,6 +18,5 @@ shadowFunction
unsafeClassCanLeak
useStlAlgorithm
uselessOverride
-va_list_usedBeforeStarted
variableScope
virtualCallInConstructor
diff --git a/include/ingen/Log.hpp b/include/ingen/Log.hpp
index 572e7b81..acbb4b6d 100644
--- a/include/ingen/Log.hpp
+++ b/include/ingen/Log.hpp
@@ -1,6 +1,6 @@
/*
This file is part of Ingen.
- Copyright 2007-2016 David Robillard <http://drobilla.net/>
+ Copyright 2007-2024 David Robillard <http://drobilla.net/>
Ingen is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free
@@ -88,6 +88,7 @@ public:
}
int vtprintf(LV2_URID type, const char* fmt, va_list args);
+ int tprintf(LV2_URID type, const char* fmt, ...);
void set_flush(bool f) { _flush = f; }
void set_trace(bool f) { _trace = f; }
diff --git a/src/Log.cpp b/src/Log.cpp
index 1c5b64d9..7ace4ce3 100644
--- a/src/Log.cpp
+++ b/src/Log.cpp
@@ -1,6 +1,6 @@
/*
This file is part of Ingen.
- Copyright 2007-2016 David Robillard <http://drobilla.net/>
+ Copyright 2007-2024 David Robillard <http://drobilla.net/>
Ingen is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free
@@ -39,37 +39,44 @@ void
Log::rt_error(const char* msg)
{
#ifndef NDEBUG
- va_list args;
- vtprintf(_uris.log_Error, msg, args);
+ tprintf(_uris.log_Error, msg);
#endif
}
void
Log::error(const std::string& msg)
{
- va_list args;
- vtprintf(_uris.log_Error, msg.c_str(), args);
+ tprintf(_uris.log_Error, msg.c_str());
}
void
Log::warn(const std::string& msg)
{
- va_list args;
- vtprintf(_uris.log_Warning, msg.c_str(), args);
+ tprintf(_uris.log_Warning, msg.c_str());
}
void
Log::info(const std::string& msg)
{
- va_list args;
- vtprintf(_uris.log_Note, msg.c_str(), args);
+ tprintf(_uris.log_Note, msg.c_str());
}
void
Log::trace(const std::string& msg)
{
+ tprintf(_uris.log_Trace, msg.c_str());
+}
+
+int
+Log::tprintf(LV2_URID type, const char* fmt, ...)
+{
va_list args;
- vtprintf(_uris.log_Trace, msg.c_str(), args);
+ va_start(args, fmt);
+
+ const int ret = vtprintf(type, fmt, args);
+
+ va_end(args);
+ return ret;
}
int
@@ -111,11 +118,10 @@ Log::vtprintf(LV2_URID type, const char* fmt, va_list args)
static int
log_vprintf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, va_list args)
{
- auto* f = static_cast<Log::Feature::Handle*>(handle);
- va_list noargs = {};
+ auto* const f = static_cast<Log::Feature::Handle*>(handle);
- int ret = f->log->vtprintf(type, f->node->path().c_str(), noargs);
- ret += f->log->vtprintf(type, ": ", noargs);
+ int ret = f->log->tprintf(type, f->node->path().c_str());
+ ret += f->log->tprintf(type, ": ");
ret += f->log->vtprintf(type, fmt, args);
return ret;