summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Levin <daniel.levin@amd.com>2023-10-13 04:31:34 -0700
committerRosen Zhelev <rosen.zhelev@arm.com>2023-10-19 08:23:09 +0000
commitd3e284cd7eda52748dc25b7c521f1bb73d3ae27a (patch)
tree4962be98001c4c6b8496e67ead47ac2eadef06d2
parent188ffe6a26a184cc2904535dd04ae4ec3c879e35 (diff)
downloadvulkan-wsi-layer-d3e284cd7eda52748dc25b7c521f1bb73d3ae27a.tar.gz
vulkan-wsi-layer-d3e284cd7eda52748dc25b7c521f1bb73d3ae27a.tar.bz2
vulkan-wsi-layer-d3e284cd7eda52748dc25b7c521f1bb73d3ae27a.zip
Fix formatting long as %d in util/log.cpp
Changed log level type from long to int, since value is expected to be a small integer in range [0-3]. Since codebase requires C++17 also replaced strtol with std::from_chars(), which will parse string as int, and skip updating the defaut value if VULKAN_WSI_DEBUG_LEVEL env var does not represent int. Signed-off-by: Daniel Levin <daniel.levin@amd.com>
-rw-r--r--util/log.cpp9
-rw-r--r--util/log.hpp2
2 files changed, 6 insertions, 5 deletions
diff --git a/util/log.cpp b/util/log.cpp
index eac9e35..c1d102e 100644
--- a/util/log.cpp
+++ b/util/log.cpp
@@ -24,6 +24,7 @@
#include "log.hpp"
#include <iostream>
+#include <charconv>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
@@ -38,16 +39,16 @@ namespace util
/**
* @brief check if a log level is enabled, and print it
*/
-static bool check_and_print_log_level(long level)
+static bool check_and_print_log_level(int level)
{
struct log_state
{
- long level = WSI_DEFAULT_LOG_LEVEL;
+ int level = WSI_DEFAULT_LOG_LEVEL;
log_state()
{
if (const char *env = std::getenv("VULKAN_WSI_DEBUG_LEVEL"))
{
- level = strtol(env, nullptr, 0);
+ std::from_chars(env, env + std::strlen(env), level);
}
}
};
@@ -78,7 +79,7 @@ static bool check_and_print_log_level(long level)
return result;
}
-void wsi_log_message(long level, const char *file, int line, const char *format, ...)
+void wsi_log_message(int level, const char *file, int line, const char *format, ...)
{
if (check_and_print_log_level(level))
{
diff --git a/util/log.hpp b/util/log.hpp
index 2bc7f2b..864df8a 100644
--- a/util/log.hpp
+++ b/util/log.hpp
@@ -45,7 +45,7 @@ namespace util
* @param[in] format A C-style formatting string.
*/
-void wsi_log_message(long level, const char *file, int line, const char *format, ...)
+void wsi_log_message(int level, const char *file, int line, const char *format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 4, 5)))
#endif