loguru icon indicating copy to clipboard operation
loguru copied to clipboard

typo in sprintf

Open ohell opened this issue 5 years ago • 1 comments

loguru.cpp, line1206: snprintf(level_buff, sizeof(level_buff) - 1, "% 4d", verbosity);

Note the space between % and 4d

ohell avatar May 10 '20 17:05 ohell

That may or may not be a typo. I believe the space prepends a space for positive numbers (and negative values will have the negative sign, as usual).

However, I think the snprintf statement is wrong anyway:

char level_buff[6];
snprintf(level_buff, sizeof(level_buff) - 1, "%s", custom_level_name);

It is idiomatic to do snprintf(buff, sizeof(buff), ...). Not sure why that -1 is there.

And indeed clang says:

warning: 'snprintf' will always be truncated; specified size is 5, but format string expands to at least 6 [-Wformat-truncation]
 1199 |                         snprintf(level_buff, sizeof(level_buff) - 1, "% 4d", verbosity);
      |                         ^

Patch: https://github.com/emilk/loguru/pull/278

seanm avatar Jun 17 '25 14:06 seanm