emilk / emilk/loguru

[GCC Warning] '% 4d' directive output may be truncated

Open
#92 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.9k
Forks
280
Avg merge
7m
Merged PRs (30d)
4

Description

I get the following warning when compiling loguru with GCC8 on Ubuntu 18.04.

```
[ 1%] Building CXX object third_party/CMakeFiles/wren_third_party.dir/loguru/loguru.cpp.o
//third_party/loguru/loguru.cpp: In function 'void loguru::print_preamble(char*, size_t, loguru::Verbosity, const char*, unsigned int)':
//third_party/loguru/loguru.cpp:1165:49: warning: '% 4d' directive output may be truncated writing between 4 and 11 bytes into a region of size 5 [-Wformat-truncation=]
snprintf(level_buff, sizeof(level_buff) - 1, "% 4d", verbosity);
^~~~~~
//third_party/loguru/loguru.cpp:1165:49: note: directive argument in the range [1, 2147483647]
In file included from /usr/include/stdio.h:862,
from /usr/include/c++/8/cstdio:42,
from /usr/include/c++/8/ext/string_conversions.h:43,
from /usr/include/c++/8/bits/basic_string.h:6391,
from /usr/include/c++/8/string:52,
from /usr/include/c++/8/bits/locale_classes.h:40,
from /usr/include/c++/8/bits/ios_base.h:41,
from /usr/include/c++/8/ios:42,
from /usr/include/c++/8/istream:38,
from /usr/include/c++/8/sstream:38,
from //third_party/loguru/loguru.hpp:1068,
from //third_party/loguru/loguru.cpp:19:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:35: note: '__builtin___snprintf_chk' output between 5 and 12 bytes into a destination of size 5
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

See:
- https://stackoverflow.com/questions/51534284/how-to-circumvent-format-truncation-warning-in-gcc
- https://gcc.gnu.org/gcc-7/changes.html
- `-Wformat-truncation=1 is included in -Wall`
- Happens here: https://github.com/emilk/loguru/blob/master/loguru.cpp#L1193

I haven't looked that much into loguru's source, so I can't say whether it's an actual problem/bug or not. :-)

I'll provide more information if requested.

Regards,
Andre

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.