fix array-bounds warning

This commit is contained in:
alandefreitas
2022-11-02 19:48:12 -03:00
committed by Alan de Freitas
parent c4f6491537
commit ffce33d483
4 changed files with 20 additions and 17 deletions

View File

@ -58,7 +58,7 @@ def main(ctx):
linux_cxx("Valgrind", "clang++-14", packages="clang-14 libc6-dbg libc++-dev libstdc++-9-dev", llvm_os="jammy", llvm_ver="14", buildscript="drone", buildtype="valgrind", image="cppalliance/droneubuntu2204:1", environment={'COMMENT': 'valgrind', 'B2_TOOLSET': 'clang-14', 'B2_CXXSTD': '11,14,17', 'B2_DEFINES': 'BOOST_NO_STRESS_TEST=1', 'B2_VARIANT': 'debug', 'B2_TESTFLAGS': 'testing.launcher=valgrind', 'VALGRIND_OPTS': '--error-exitcode=1'}, globalenv=globalenv),
# arm64 (unsigned char)
linux_cxx("ARM64: GCC 11", "g++-11", packages="g++-11", buildscript="drone", buildtype="boost", image="cppalliance/droneubuntu2004:multiarch", environment={'B2_TOOLSET': 'gcc-11', 'B2_CXXFLAGS': '-Werror -Wno-error=array-bounds -Wno-error=stringop-overflow', 'B2_CXXSTD': '17,20'}, arch="arm64", globalenv=globalenv),
linux_cxx("ARM64: GCC 11", "g++-11", packages="g++-11", buildscript="drone", buildtype="boost", image="cppalliance/droneubuntu2004:multiarch", environment={'B2_TOOLSET': 'gcc-11', 'B2_CXXFLAGS': '-Werror -Wno-error=stringop-overflow', 'B2_CXXSTD': '17,20'}, arch="arm64", globalenv=globalenv),
# s390x
linux_cxx("S390x: Clang 12", "clang++-12", packages="clang-12 libstdc++-9-dev", llvm_os="focal", llvm_ver="12", buildtype="boost", buildscript="drone", image="cppalliance/droneubuntu2004:multiarch", environment={'B2_TOOLSET': 'clang-12', 'B2_CXXFLAGS': '-Werror', 'B2_CXXSTD': '17,20'}, arch="s390x", globalenv=globalenv),
@ -82,10 +82,10 @@ def main(ctx):
linux_cxx("GCC 5: C++11", "g++-5", packages="g++-5", buildscript="drone", buildtype="boost", image=linuxglobalimage, environment={'B2_TOOLSET': 'gcc-5', 'B2_CXXFLAGS': '-Werror', 'B2_CXXSTD': '11'}, globalenv=globalenv),
linux_cxx("GCC 6: C++11,14", "g++-6", packages="g++-6", buildscript="drone", buildtype="boost", image=linuxglobalimage, environment={'B2_TOOLSET': 'gcc-6', 'B2_CXXFLAGS': '-Werror -Wno-error=unused-function', 'B2_CXXSTD': '11,14'}, globalenv=globalenv),
linux_cxx("GCC 7: C++14,17", "g++-7", packages="g++-7", buildscript="drone", buildtype="boost", image=linuxglobalimage, environment={'B2_TOOLSET': 'gcc-7', 'B2_CXXFLAGS': '-Werror -Wno-error=unused-function -Wno-error=noexcept-type', 'B2_CXXSTD': '14,17'}, globalenv=globalenv),
linux_cxx("GCC 8: C++17", "g++-8", packages="g++-8", buildscript="drone", buildtype="boost", image=linuxglobalimage, environment={'B2_TOOLSET': 'gcc-8', 'B2_CXXFLAGS': '-Werror -Wno-error=unused-function -Wno-error=array-bounds', 'B2_CXXSTD': '17'}, globalenv=globalenv),
linux_cxx("GCC 8: C++17", "g++-8", packages="g++-8", buildscript="drone", buildtype="boost", image=linuxglobalimage, environment={'B2_TOOLSET': 'gcc-8', 'B2_CXXFLAGS': '-Werror -Wno-error=unused-function', 'B2_CXXSTD': '17'}, globalenv=globalenv),
linux_cxx("GCC 9: C++17", "g++-9", packages="g++-9", buildscript="drone", buildtype="boost", image=linuxglobalimage, environment={'B2_TOOLSET': 'gcc-9', 'B2_CXXFLAGS': '-Werror', 'B2_CXXSTD': '17'}, globalenv=globalenv),
linux_cxx("GCC 10: C++17", "g++-10", packages="g++-10", buildscript="drone", buildtype="boost", image=linuxglobalimage, environment={'B2_TOOLSET': 'gcc-10', 'B2_CXXFLAGS': '-Werror -funsigned-char -Wno-error=array-bounds', 'B2_CXXSTD': '17'}, globalenv=globalenv),
linux_cxx("GCC 11: C++17,20", "g++-11", packages="g++-11", buildscript="drone", buildtype="boost", image=linuxglobalimage, environment={'B2_TOOLSET': 'gcc-11', 'B2_CXXFLAGS': '-Werror -Wno-error=array-bounds -Wno-error=stringop-overflow', 'B2_CXXSTD': '17,20'}, globalenv=globalenv),
linux_cxx("GCC 10: C++17", "g++-10", packages="g++-10", buildscript="drone", buildtype="boost", image=linuxglobalimage, environment={'B2_TOOLSET': 'gcc-10', 'B2_CXXFLAGS': '-Werror -funsigned-char', 'B2_CXXSTD': '17'}, globalenv=globalenv),
linux_cxx("GCC 11: C++17,20", "g++-11", packages="g++-11", buildscript="drone", buildtype="boost", image=linuxglobalimage, environment={'B2_TOOLSET': 'gcc-11', 'B2_CXXFLAGS': '-Werror -Wno-error=stringop-overflow', 'B2_CXXSTD': '17,20'}, globalenv=globalenv),
# Clang (All other versions)
linux_cxx("Clang 4.0: C++11,14", "clang++-4.0", packages="clang-4.0 libstdc++-6-dev", llvm_os="xenial", llvm_ver="4.0", buildscript="drone", buildtype="boost", image="cppalliance/droneubuntu1804:1", environment={'B2_TOOLSET': 'clang-4.0', 'B2_CXXFLAGS': '', 'B2_CXXSTD': '11,14'}, globalenv=globalenv),
@ -105,7 +105,7 @@ def main(ctx):
linux_cxx("ARM64: Clang 12", "clang++-12", packages="clang-12 libstdc++-9-dev", llvm_os="focal", llvm_ver="12", buildscript="drone", buildtype="boost", image="cppalliance/droneubuntu2004:multiarch", environment={'B2_TOOLSET': 'clang-12', 'B2_CXXFLAGS': '-Werror', 'B2_CXXSTD': '11,14,17,20'}, arch="arm64", globalenv=globalenv),
# s390x
linux_cxx("S390x: GCC 11", "g++-11", packages="g++-11", buildtype="boost", buildscript="drone", image="cppalliance/droneubuntu2004:multiarch", environment={'B2_TOOLSET': 'gcc-11', 'B2_CXXFLAGS': '-Werror -Wno-error=array-bounds', 'B2_CXXSTD': '17'}, arch="s390x", globalenv=globalenv),
linux_cxx("S390x: GCC 11", "g++-11", packages="g++-11", buildtype="boost", buildscript="drone", image="cppalliance/droneubuntu2004:multiarch", environment={'B2_TOOLSET': 'gcc-11', 'B2_CXXFLAGS': '-Werror', 'B2_CXXSTD': '17'}, arch="s390x", globalenv=globalenv),
# MSVC
windows_cxx("MSVC 14.1", "", image="cppalliance/dronevs2017", buildtype="boost", buildscript="drone", environment={"B2_TOOLSET": "msvc-14.1", 'B2_CXXFLAGS': '/WX', "B2_CXXSTD": "11,14,17"},globalenv=globalenv),

View File

@ -89,6 +89,7 @@ else ()
INTERFACE
Boost::assert
Boost::container_hash
Boost::core
Boost::static_assert
Boost::throw_exception
Boost::utility

View File

@ -14,6 +14,7 @@
// External include guard
#ifndef BOOST_STATIC_STRING_CONFIG_HPP
#include <boost/static_string/config.hpp>
#include <boost/config/workaround.hpp>
#endif
#include <algorithm>
@ -28,6 +29,13 @@
namespace boost {
namespace static_strings {
#if BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 80000)
#pragma GCC diagnostic push // false positives
#pragma GCC diagnostic ignored "-Warray-bounds"
#pragma GCC diagnostic ignored "-Wrestrict"
#pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif
#ifndef BOOST_STATIC_STRING_DOCS
template<std::size_t N, typename CharT, typename Traits>
class basic_static_string;
@ -6090,22 +6098,13 @@ insert(
if (offset < index)
{
const size_type diff = index - offset;
#if BOOST_WORKAROUND( BOOST_GCC, >= 120000 )
detail::copy_with_traits<Traits>(&curr_data[offset], &curr_data[offset] + diff, dest);
detail::copy_with_traits<Traits>(dest + count, dest + 2 * count - diff, &curr_data[index + diff]);
#else
traits_type::copy(dest, &curr_data[offset], diff);
traits_type::copy(&curr_data[index + diff], dest + count, count - diff);
#endif
}
else
{
auto src = &curr_data[offset + count];
#if BOOST_WORKAROUND( BOOST_GCC, >= 120000 )
detail::copy_with_traits<Traits>(src, src + count, dest);
#else
traits_type::copy(dest, src, count);
#endif
}
}
this->set_size(curr_size + count);
@ -6565,6 +6564,11 @@ insert_unchecked(
this->set_size(curr_size + count);
return curr_data + index;
}
#if BOOST_WORKAROUND(BOOST_GCC_VERSION, >= 80000)
#pragma GCC diagnostic pop
#endif
} // static_strings
} // boost
#endif

View File

@ -21,7 +21,5 @@ add_executable(boost_static_string_tests ${BOOST_STATIC_STRING_TESTS_FILES})
# The include dependencies are found in the CMakeLists.txt
# of the root project directory.
# See: BOOST_STATIC_STRING_UNIT_TEST_LIBRARIES
target_link_libraries(boost_static_string_tests PRIVATE
Boost::static_string
Boost::core)
target_link_libraries(boost_static_string_tests PRIVATE Boost::static_string)
add_test(NAME boost_static_string_tests COMMAND boost_static_string_tests)