mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-21 11:55:31 -04:00
universal7885: liblogformat: Add helpers to avoid -Wformat-security warns/errors
- Also make warning if LOG_TAG is not defined
This commit is contained in:
parent
60659bf10c
commit
917fc7ecf1
1 changed files with 24 additions and 1 deletions
|
|
@ -1,8 +1,19 @@
|
|||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#ifdef LOG_TAG
|
||||
|
||||
#include <log/log.h>
|
||||
|
||||
#define make_str(a, ...) _make_str(__FILE__, __LINE__, a, ##__VA_ARGS__).c_str()
|
||||
|
||||
// Helpers to avoid -Wformat-security
|
||||
#define LOG_E(fmt, ...) ALOGE("%s", make_str(fmt, ##__VA_ARGS__))
|
||||
#define LOG_W(fmt, ...) ALOGW("%s", make_str(fmt, ##__VA_ARGS__))
|
||||
#define LOG_I(fmt, ...) ALOGI("%s", make_str(fmt, ##__VA_ARGS__))
|
||||
#define LOG_D(fmt, ...) ALOGD("%s", make_str(fmt, ##__VA_ARGS__))
|
||||
#define LOG_V(fmt, ...) ALOGV("%s", make_str(fmt, ##__VA_ARGS__))
|
||||
|
||||
template <typename... Args>
|
||||
std::string _make_str(const std::string& filename, int line, const std::string& fmt, Args... args) {
|
||||
#pragma clang diagnostic push
|
||||
|
|
@ -14,4 +25,16 @@ std::string _make_str(const std::string& filename, int line, const std::string&
|
|||
std::stringstream ss;
|
||||
ss << "[" << filename << ":" << line << "] " << std::string(buf.begin(), buf.end());
|
||||
return ss.str();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#warning LOG_TAG is not defined, disabling logging.
|
||||
|
||||
#define LOG_E(...) do {} while(0)
|
||||
#define LOG_W(...) do {} while(0)
|
||||
#define LOG_I(...) do {} while(0)
|
||||
#define LOG_D(...) do {} while(0)
|
||||
#define LOG_V(...) do {} while(0)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue