Commit 8a7a4ef7 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

moved warning switches from top of the file to the printf statements"

parent 89cdd71f
......@@ -13,16 +13,11 @@ std::string argvToString(int argc, const char **argv);
namespace MpMO
{
/* ---- CAUTION ---- */
/* In this entire namespace the warnings -Wformat-nonliteral and -Wformat-security are disabled
/* In this entire namespace the warnings -Wformat-nonliteral and -Wformat-security are disabled for all printf statements
* this can cause security issues IF the users have access to the format strings used in this files.
* in CDO this is not the case and as such it was decided to use this file as it is and to disable the warnings.
*
* At the end of this namespace these warnings are reenabled and should not be disabled for the rest of the program
* */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#pragma GCC diagnostic ignored "-Wformat-security"
/* ---- CAUTION ---- */
extern int DebugLevel;
extern bool silentMode;
......@@ -51,14 +46,22 @@ template <typename... Args>
void
Print(const std::string &format, Args const &... args) noexcept
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#pragma GCC diagnostic ignored "-Wformat-security"
if (!silentMode) printf((format + "\n").c_str(), Argument(args)...);
#pragma GCC diagnostic pop
}
template <typename... Args>
void
PrintCerr(const std::string &format, Args const &... args) noexcept
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#pragma GCC diagnostic ignored "-Wformat-security"
fprintf(stderr, (format + "\n").c_str(), Argument(args)...);
#pragma GCC diagnostic pop
}
static inline std::string
......@@ -74,16 +77,24 @@ template <typename... Args>
void
Debug_(const char *p_func, int p_debugScope, const std::string &format, Args const &... args)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#pragma GCC diagnostic ignored "-Wformat-security"
if (p_debugScope)
fprintf(stderr,(Cyan("deb: ") + std::string(p_func) + get_padding(p_func) + format + "\n").c_str(), Argument(args)...);
#pragma GCC diagnostic pop
}
template <typename... Args>
void
Debug_(const char *p_func, const std::string &format, Args const &... args)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#pragma GCC diagnostic ignored "-Wformat-security"
if (DebugLevel)
fprintf(stderr, (Cyan("deb: ") + std::string(p_func) + get_padding(p_func) + format + "\n").c_str(), Argument(args)...);
#pragma GCC diagnostic pop
}
template <typename... Args>
......@@ -125,7 +136,6 @@ SysError_(const std::string &format, Args const &... args) noexcept
exit(EXIT_FAILURE);
}
#pragma GCC diagnostic pop
} // namespace MpMO
#define Verbose(...) Verbose_(__VA_ARGS__)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment