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

Tests fail to compile: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage], etc #828

Closed
yurivict opened this issue Nov 9, 2023 · 2 comments

Comments

@yurivict
Copy link

yurivict commented Nov 9, 2023

/usr/ports/devel/doctest/work/doctest-2.4.11/doctest/parts/doctest_fwd.h:1177:61: error: 'in' is an unsafe buffer that does not perform bounds checks [-Werror,-Wunsafe-buffer-usage]
        static void fill(std::ostream* stream, const char (&in)[N]) {
                                               ~~~~~~~~~~~~~^~~~~~
/usr/ports/devel/doctest/work/doctest-2.4.11/doctest/parts/doctest_fwd.h:1050:22: note: in instantiation of member function 'doctest::detail::filldata<const char[3]>::fill' requested here
        filldata<T>::fill(stream, in);
                     ^
/usr/ports/devel/doctest/work/doctest-2.4.11/doctest/parts/doctest_fwd.h:1057:9: note: in instantiation of function template specialization 'doctest::detail::filloss<const char[3]>' requested here
        filloss<typename types::remove_reference<decltype(in)>::type>(stream, in);
        ^

In file included from /usr/ports/devel/doctest/work/doctest-2.4.11/examples/all_features/main.cpp:2:
In file included from /usr/ports/devel/doctest/work/doctest-2.4.11/scripts/development_only/doctest/doctest.h:1:
/usr/ports/devel/doctest/work/doctest-2.4.11/doctest/parts/doctest_fwd.h:608:47: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
    bool isOnStack() const noexcept { return (buf[last] & 128) == 0; }
                                              ^~~
In file included from /usr/ports/devel/doctest/work/doctest-2.4.11/examples/all_features/main.cpp:2:
In file included from /usr/ports/devel/doctest/work/doctest-2.4.11/scripts/development_only/doctest/doctest.h:5:
/usr/ports/devel/doctest/work/doctest-2.4.11/doctest/parts/doctest.cpp:217:29: error: 'a' is an unsafe pointer used for buffer access [-Werror,-Wunsafe-buffer-usage]
    int stricmp(const char* a, const char* b) {
                ~~~~~~~~~~~~^
/usr/ports/devel/doctest/work/doctest-2.4.11/doctest/parts/doctest.cpp:218:16: note: used in pointer arithmetic here
        for(;; a++, b++) {
               ^
/usr/ports/devel/doctest/work/doctest-2.4.11/doctest/parts/doctest.cpp:217:44: error: 'b' is an unsafe pointer used for buffer access [-Werror,-Wunsafe-buffer-usage]
    int stricmp(const char* a, const char* b) {
                               ~~~~~~~~~~~~^
/usr/ports/devel/doctest/work/doctest-2.4.11/doctest/parts/doctest.cpp:218:21: note: used in pointer arithmetic here
        for(;; a++, b++) {
                    ^
/usr/ports/devel/doctest/work/doctest-2.4.11/doctest/parts/doctest.cpp:510:9: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
        buf[sz] = '\0';
        ^~~
/usr/ports/devel/doctest/work/doctest-2.4.11/doctest/parts/doctest.cpp:518:9: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
        data.ptr[sz] = '\0';
        ^~~~~~~~

Version: 2.4.11
clang-16
FreeBSD 13.2

@mitchgrout
Copy link

This could be resolved via the addition of DOCTEST_CLANG_SUPPRESS_WARNING("-Wunsafe-buffer-usage") into the DOCTEST_SUPPRESS_COMMON_WARNINGS_PUSH macro. The warning appears to be hinting towards using STL types such as std::span or std::array in place of a plain array/pointer, however that probably shouldn't be applicable to a library like this.

@yurivict
Copy link
Author

Thank you.

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

2 participants