-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Invalid garbage characters showing around formatted data #1447
Comments
I guess character encoding and data type problems. spdlog formats log messages with the fmt library. Look at the output of building the code below on my Windows machine. #include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_sinks.h"
#include <locale>
int main(int, char**)
{
auto console = std::make_shared<spdlog::sinks::stdout_sink_mt>();
auto logger =
std::make_shared<spdlog::logger>("console", console);
spdlog::register_logger(logger);
std::locale locale;
logger->info("my locale={}", locale.name());
char ch = 192;
logger->info("Tested, OK: {}", ch);
int num = 192;
logger->info("Tested, OK: {}", num);
spdlog::shutdown();
return 0;
} Console: $ chcp 1252
$ spdlog_issue_1050.exe
[2020-02-19 10:05:27.146] [console] [info] my locale=C
[2020-02-19 10:05:27.148] [console] [info] Tested, OK: À
[2020-02-19 10:05:27.149] [console] [info] Tested, OK: 192 When 192 is formatted as char type, "À" is printed. Check the data types that are formatted in your code, and provide code that can reproduce the issue. |
The types that are formatted are To make things worse, the values that are output change every time the program is run which lead to my conclusion that it must be referencing garbage memory somewhere. See here for a second run of the same binary file to compare to the first image: This does not sound like the issue you describe to me personally. I am running an identical binary file on my side and have correct formatting. The only alternate idea I have is to run a debugger remotely and see where these values are coming from. I can try directly using the fmt library too? |
Can you isolate the problem? |
I have now narrowed it down and reproduced it using a |
If you determine that it is not related to spdlog, close this issue. |
Upon double checking, fmt is indeed the cause. It uses See fmtlib/fmt#519. |
Which fmt version are you using? seems like an old issue that was fixed long time ago.. |
I am using the latest. It looks like some compilers will compile the Other examples: https://stackoverflow.com/a/40621975. |
@Crunkle As a reference for users who might encounter this issue, could you please provide the spec of the bad build env (compiler version, os version, cpu)? |
Sure, although do note that I was using unstable versions of LLVM and MinGW. Specifically, I am using an older version of Clang 9.0 targeting The affected machine was running a Haswell i7 4790k on the latest Windows 10. I am only able to reproduce it on Haswell and earlier processors. I do not think that many users will have trouble with this. The toolchain I am using is very unstable and only suitable for development, but I hope this helps if any future issues arise! |
Thanks for the info! |
I am seeing invalid characters appear around formatted numbers on (some) systems using multilingual locales. Attached is an example image - the left side is the output I see (en-US) and the right side is from a friend's system (fr-CA):
Where the output is written for all values like this:
I am using the
v1.5.0
tagged commit, but the same issue occurs on the latest branch. As far as I have tested, using a regularprintf
gives the correct output without any garbage.The text was updated successfully, but these errors were encountered: