Skip to content
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

stringop-overflow warning in 8.1.1 on g++ (GCC) 10.2.1 20200804 #2708

Closed
andrewkcorcoran opened this issue Jan 10, 2022 · 6 comments
Closed

Comments

@andrewkcorcoran
Copy link

In function ‘copy2’,
    inlined from ‘format_decimal’ at /local/1/home/build/gcc/_deps/fmt-src/include/fmt/format.h:1124:8,
    inlined from ‘format_decimal’ at /local/1/home/build/gcc/_deps/fmt-src/include/fmt/format.h:1134:28,
    inlined from ‘write.constprop’ at /local/1/home/build/gcc/_deps/fmt-src/include/fmt/chrono.h:1663:36:
/local/1/home/build/gcc/_deps/fmt-src/include/fmt/format.h:1090:11: error: writing 2 bytes into a region of size 0 [-Werror=stringop-overflow=]
 1090 |     memcpy(dst, src, 2);
      |           ^
/local/1/home/build/gcc/_deps/fmt-src/include/fmt/chrono.h: In member function ‘write.constprop’:
/local/1/home/build/gcc/_deps/fmt-src/include/fmt/format.h:1133:8: note: at offset -2 to object ‘buffer’ with size 10 declared here
 1133 |   Char buffer[digits10<UInt>() + 1];
      |        ^
In function ‘format_decimal’,
    inlined from ‘format_decimal’ at /local/1/home/build/gcc/_deps/fmt-src/include/fmt/format.h:1134:28,
    inlined from ‘write.constprop’ at /local/1/home/build/gcc/_deps/fmt-src/include/fmt/chrono.h:1663:36:
/local/1/home/build/gcc/_deps/fmt-src/include/fmt/format.h:1120:12: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
 1120 |     *--out = static_cast<Char>('0' + value);
      |            ^
/local/1/home/build/gcc/_deps/fmt-src/include/fmt/chrono.h: In member function ‘write.constprop’:
/local/1/home/build/gcc/_deps/fmt-src/include/fmt/format.h:1133:8: note: at offset -1 to object ‘buffer’ with size 10 declared here
 1133 |   Char buffer[digits10<UInt>() + 1];
@vitaut
Copy link
Contributor

vitaut commented Jan 10, 2022

Please provide a repro (preferably on godbolt).

@andrewkcorcoran
Copy link
Author

andrewkcorcoran commented Jan 11, 2022

A simple fmt::format("{}", std::chrono::nanoseconds{0}); reproduces it on my system but not on godbolt. Possibly a bug in GCC10?

/opt/rh/devtoolset-10/root/usr/bin/c++ -DFMT_LOCALE -I/local/1/home/build/gcc/_deps/fmt-src/include  -g -march=native -fno-var-tracking-assignments -Werror -Wall -Wextra -Wpedantic -Wshadow -Wnon-virtual-dtor     -Wold-style-cast -Wunused -Woverloaded-virtual -Wdouble-promotion -O3 -DNDEBUG   -std=c++2a -o CMakeFiles/fmt_test.dir/fmt.cpp.o -c /local/1/home/source/bin/fmt.cpp

@phprus
Copy link
Contributor

phprus commented Jan 11, 2022

This is a bug in GCC: #2442 (comment)

@andrewkcorcoran
Copy link
Author

andrewkcorcoran commented Jan 11, 2022

Ah ok :/. Is there a known workaround when using fmt that doesn't involve globally disabling this warning for the project including fmt?

@vitaut
Copy link
Contributor

vitaut commented Jan 11, 2022

You can set the FMT_SYSTEM_HEADERS cmake variable as a workaround.

@vitaut vitaut closed this as completed Jan 11, 2022
@vitaut vitaut changed the title Compiler error in 8.1.1 on g++ (GCC) 10.2.1 20200804 stringop-overflow warning in 8.1.1 on g++ (GCC) 10.2.1 20200804 Jan 11, 2022
dr7ana added a commit to dr7ana/libquic that referenced this issue Jun 4, 2024
- FMT will trigger a gcc bug on stringop-overflow with gcc versions 11 and earlier
- FMT issue fmtlib/fmt#2442
- FMT issue fmtlib/fmt#2708
- GCC bug tracker https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101854
- Confirming it still appears on gcc-11 https://godbolt.org/z/d15q4Exvz
dr7ana added a commit to dr7ana/libquic that referenced this issue Jun 4, 2024
- FMT will trigger a gcc bug on stringop-overflow with gcc versions 11 and earlier
- FMT issue fmtlib/fmt#2442
- FMT issue fmtlib/fmt#2708
- GCC bug tracker https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101854
- Confirming it still appears on gcc-11 https://godbolt.org/z/d15q4Exvz
dr7ana added a commit to dr7ana/libquic that referenced this issue Jun 4, 2024
- FMT will trigger a gcc bug on stringop-overflow with gcc versions 11 and earlier
- FMT issue fmtlib/fmt#2442
- FMT issue fmtlib/fmt#2708
- GCC bug tracker https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101854
- Confirming it still appears on gcc-11 https://godbolt.org/z/d15q4Exvz
dr7ana added a commit to dr7ana/libquic that referenced this issue Jun 4, 2024
- FMT will trigger a gcc bug on stringop-overflow with gcc versions 11 and earlier
- FMT issue fmtlib/fmt#2442
- FMT issue fmtlib/fmt#2708
- GCC bug tracker https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101854
- Confirming it still appears on gcc-11 https://godbolt.org/z/d15q4Exvz
dr7ana added a commit to dr7ana/libquic that referenced this issue Jun 4, 2024
- FMT will trigger a gcc bug on stringop-overflow with gcc versions 11 and earlier
- FMT issue fmtlib/fmt#2442
- FMT issue fmtlib/fmt#2708
- GCC bug tracker https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101854
- Confirming it still appears on gcc-11 https://godbolt.org/z/d15q4Exvz
@vitaut
Copy link
Contributor

vitaut commented Jul 22, 2024

The false positive has been worked around in 7f157dc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants