From 89bde7c6e85ab50de988fb3f7b91d2041b41a4cb Mon Sep 17 00:00:00 2001 From: Laptop Windows Date: Wed, 21 Feb 2024 20:36:22 -0500 Subject: [PATCH] warnings --- include/blt/std/logging.h | 35 ++++++++++++++++++++------------ include/blt/std/time.h | 42 ++++++++++++++++++++++----------------- src/blt/std/assert.cpp | 17 +++++++++++++++- 3 files changed, 62 insertions(+), 32 deletions(-) diff --git a/include/blt/std/logging.h b/include/blt/std/logging.h index f8d0210..de24877 100644 --- a/include/blt/std/logging.h +++ b/include/blt/std/logging.h @@ -319,17 +319,17 @@ namespace blt::logging { } }; -#define BLT_NOW() auto t = std::time(nullptr); auto now = std::localtime(&t) - #define BLT_ISO_YEAR(S) auto S = std::to_string(now->tm_year + 1900); \ +#define BLT_NOW() auto t = std::time(nullptr); tm now; localtime_s(&now, &t); //auto now = std::localtime(&t) + #define BLT_ISO_YEAR(S) auto S = std::to_string(now.tm_year + 1900); \ S += '-'; \ - S += ensureHasDigits(now->tm_mon+1, 2); \ + S += ensureHasDigits(now.tm_mon+1, 2); \ S += '-'; \ - S += ensureHasDigits(now->tm_mday, 2); - #define BLT_CUR_TIME(S) auto S = ensureHasDigits(now->tm_hour, 2); \ + S += ensureHasDigits(now.tm_mday, 2); + #define BLT_CUR_TIME(S) auto S = ensureHasDigits(now.tm_hour, 2); \ S += ':'; \ - S += ensureHasDigits(now->tm_min, 2); \ + S += ensureHasDigits(now.tm_min, 2); \ S += ':'; \ - S += ensureHasDigits(now->tm_sec, 2); + S += ensureHasDigits(now.tm_sec, 2); static inline std::string ensureHasDigits(int current, int digits) { std::string asString = std::to_string(current); @@ -352,27 +352,27 @@ namespace blt::logging { const std::unique_ptr tagMap = std::make_unique(tag_map{ {"YEAR", [](const tag_func_param&) -> std::string { BLT_NOW(); - return std::to_string(now->tm_year); + return std::to_string(now.tm_year); }}, {"MONTH", [](const tag_func_param&) -> std::string { BLT_NOW(); - return ensureHasDigits(now->tm_mon+1, 2); + return ensureHasDigits(now.tm_mon+1, 2); }}, {"DAY", [](const tag_func_param&) -> std::string { BLT_NOW(); - return ensureHasDigits(now->tm_mday, 2); + return ensureHasDigits(now.tm_mday, 2); }}, {"HOUR", [](const tag_func_param&) -> std::string { BLT_NOW(); - return ensureHasDigits(now->tm_hour, 2); + return ensureHasDigits(now.tm_hour, 2); }}, {"MINUTE", [](const tag_func_param&) -> std::string { BLT_NOW(); - return ensureHasDigits(now->tm_min, 2); + return ensureHasDigits(now.tm_min, 2); }}, {"SECOND", [](const tag_func_param&) -> std::string { BLT_NOW(); - return ensureHasDigits(now->tm_sec, 2); + return ensureHasDigits(now.tm_sec, 2); }}, {"MS", [](const tag_func_param&) -> std::string { return std::to_string(std::chrono::duration_cast( @@ -674,6 +674,11 @@ namespace blt::logging { #endif +#if defined(__clang__) || defined(__llvm__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" +#endif + #ifdef BLT_DISABLE_LOGGING #define BLT_LOG(format, level, ...) #define BLT_LOG_STREAM(level) @@ -753,4 +758,8 @@ namespace blt::logging { #endif #endif +#if defined(__clang__) || defined(__llvm__) +#pragma clang diagnostic pop +#endif + #endif //BLT_TESTS_LOGGING2_H diff --git a/include/blt/std/time.h b/include/blt/std/time.h index daec649..ade6954 100644 --- a/include/blt/std/time.h +++ b/include/blt/std/time.h @@ -86,19 +86,21 @@ namespace blt::system static inline std::string getTimeString() { auto t = std::time(nullptr); - auto now = std::localtime(&t); + tm now{}; + localtime_s(&now, &t); + //auto now = std::localtime(&t); std::stringstream timeString; - timeString << (1900 + now->tm_year); + timeString << (1900 + now.tm_year); timeString << "-"; - timeString << (1 + now->tm_mon); + timeString << (1 + now.tm_mon); timeString << "-"; - timeString << now->tm_mday; + timeString << now.tm_mday; timeString << " "; - timeString << now->tm_hour; + timeString << now.tm_hour; timeString << ":"; - timeString << now->tm_min; + timeString << now.tm_min; timeString << ":"; - timeString << now->tm_sec; + timeString << now.tm_sec; return timeString.str(); } @@ -110,13 +112,15 @@ namespace blt::system static inline std::string getTimeStringLog() { auto t = std::time(nullptr); - auto now = std::localtime(&t); + tm now{}; + localtime_s(&now, &t); + //auto now = std::localtime(&t); std::string timeString = "["; - timeString += ensureHasDigits(now->tm_hour, 2); + timeString += ensureHasDigits(now.tm_hour, 2); timeString += ":"; - timeString += ensureHasDigits(now->tm_min, 2); + timeString += ensureHasDigits(now.tm_min, 2); timeString += ":"; - timeString += ensureHasDigits(now->tm_sec, 2); + timeString += ensureHasDigits(now.tm_sec, 2); timeString += "] "; return timeString; } @@ -127,19 +131,21 @@ namespace blt::system static inline std::string getTimeStringFS() { auto t = std::time(nullptr); - auto now = std::localtime(&t); + tm now{}; + localtime_s(&now, &t); + //auto now = std::localtime(&t); std::stringstream timeString; - timeString << (1900 + now->tm_year); + timeString << (1900 + now.tm_year); timeString << "-"; - timeString << (1 + now->tm_mon); + timeString << (1 + now.tm_mon); timeString << "-"; - timeString << now->tm_mday; + timeString << now.tm_mday; timeString << "_"; - timeString << now->tm_hour; + timeString << now.tm_hour; timeString << "-"; - timeString << now->tm_min; + timeString << now.tm_min; timeString << "-"; - timeString << now->tm_sec; + timeString << now.tm_sec; return timeString.str(); } } diff --git a/src/blt/std/assert.cpp b/src/blt/std/assert.cpp index 229f46a..046aad8 100644 --- a/src/blt/std/assert.cpp +++ b/src/blt/std/assert.cpp @@ -30,7 +30,8 @@ #endif namespace blt { - + +#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) static inline std::string _macro_filename(const std::string& path){ auto paths = blt::string::split(path, "/"); auto final = paths[paths.size()-1]; @@ -38,6 +39,7 @@ namespace blt { return paths[paths.size()-2]; return final; } +#endif void b_throw(const char* what, const char* path, int line) { @@ -49,6 +51,10 @@ namespace blt { printStacktrace(messages, size, path, line); BLT_FREE_STACK_TRACE(); +#else + (void) what; + (void) path; + (void) line; #endif } @@ -66,6 +72,10 @@ namespace blt { BLT_FREE_STACK_TRACE(); #endif + (void) expression; + (void) msg; + (void) path; + (void) line; } void printStacktrace(char** messages, int size, const char* path, int line) @@ -106,7 +116,12 @@ namespace blt { BLT_ERROR(buffer); } +#else + (void) size; + (void) path; + (void) line; #endif + }