-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a compilation warning - directive output may be truncated #187
Fix a compilation warning - directive output may be truncated #187
Conversation
Add a simple solution to a compilation warning that doesn't require any special changes to be made to already existing enums, types or logic. loguru/loguru.cpp: In function ‘void loguru::print_preamble(char*, size_t, loguru::Verbosity, const char*, unsigned int)’: loguru/loguru.cpp:1208:50: warning: ‘% 4d’ directive output may be truncated writing between 4 and 11 bytes into a region of size 5 [-Wformat-truncation=] 1208 | snprintf(level_buff, sizeof(level_buff) - 1, "% 4d", verbosity); | ^~~~ loguru/loguru.cpp:1208:49: note: directive argument in the range [1, 2147483647] 1208 | snprintf(level_buff, sizeof(level_buff) - 1, "% 4d", verbosity); | ^~~~~~ In file included from /usr/include/stdio.h:867, from /usr/include/c++/9/cstdio:42, from /usr/include/c++/9/ext/string_conversions.h:43, from /usr/include/c++/9/bits/basic_string.h:6493, from /usr/include/c++/9/string:55, from /usr/include/c++/9/stdexcept:39, from /usr/include/c++/9/array:39, from /usr/include/c++/9/tuple:39, from /usr/include/c++/9/functional:54, from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13, from /usr/include/c++/9/algorithm:71, from loguru/loguru.cpp:36: /usr/include/x86_64-linux-gnu/bits/stdio2.h:67:35: note: ‘__builtin___snprintf_chk’ output between 5 and 12 bytes into a destination of size 5 67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 68 | __bos (__s), __fmt, __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can you please format the description by using |
loguru.cpp
Outdated
@@ -1311,7 +1311,7 @@ namespace loguru | |||
if (custom_level_name) { | |||
snprintf(level_buff, sizeof(level_buff) - 1, "%s", custom_level_name); | |||
} else { | |||
snprintf(level_buff, sizeof(level_buff) - 1, "% 4d", verbosity); | |||
snprintf(level_buff, sizeof(level_buff) - 1, "% 4d", (int8_t)verbosity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could be more explicit and do static_cast<int8_t>(verbosity)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sure, why not. Just keep in mind that all of this was a slightly hackish solution to begin with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Add a simple solution to a compilation warning that doesn't require any special changes to be made to already existing enums, types or logic.