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

Add fsanitize=integer to tests and fix all issues #817

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
factors: |
gcc ASan Shared No-Threads
msvc Shared x86
clang Time-Trace Fuzz ASan+UBSan
clang Time-Trace Fuzz ASan+UBSan IntegerSan
mingw Shared
trace-commands: true

Expand Down Expand Up @@ -151,9 +151,9 @@ jobs:
echo 'CMAKE_GENERATOR_TOOLSET=${{ matrix.generator-toolset || '' }}' >> $GITHUB_ENV
echo 'CMAKE_BUILD_TYPE=${{ matrix.build-type || '' }}' >> $GITHUB_ENV
echo 'CC=${{ steps.setup-cpp.outputs.cc || matrix.cc || '' }}' >> $GITHUB_ENV
echo 'CFLAGS=${{ matrix.ccflags || '' }}' >> $GITHUB_ENV
echo 'CFLAGS=${{ (matrix.integersan && '-fsanitize=integer -fno-sanitize=unsigned-integer-overflow -fno-sanitize-recover=integer -fno-omit-frame-pointer') || matrix.ccflags || '' }}' >> $GITHUB_ENV
echo 'CXX=${{ steps.setup-cpp.outputs.cxx || matrix.cxx || '' }}' >> $GITHUB_ENV
echo 'CXXFLAGS=${{ matrix.cxxflags || '' }}' >> $GITHUB_ENV
echo 'CXXFLAGS=${{ (matrix.integersan && '-fsanitize=integer -fno-sanitize=unsigned-integer-overflow -fno-sanitize-recover=integer -fno-omit-frame-pointer') || matrix.cxxflags || '' }}' >> $GITHUB_ENV
echo 'CXXSTD=${{ matrix.latest-cxxstd || '' }}' >> $GITHUB_ENV
echo 'BUILD_SHARED_LIBS=${{ matrix.shared || '' }}' >> $GITHUB_ENV
echo 'CMAKE_RUN_TESTS=true' >> $GITHUB_ENV
Expand All @@ -180,11 +180,11 @@ jobs:
if: matrix.is-no-factor-intermediary != 'true'
with:
source-dir: ../boost-root
build-dir: __build_cmake__
build-dir: build_cmake
build-target: tests
install: true
install-prefix: .local
cmake-version: '>=3.15'
cmake-version: '>=3.20'
extra-args: |
-D Boost_VERBOSE=ON
-D BOOST_INCLUDE_LIBRARIES=${{ steps.patch.outputs.module }}
Expand All @@ -200,9 +200,9 @@ jobs:
if: matrix.is-no-factor-intermediary != 'true'
with:
source-dir: ../boost-root/libs/${{ steps.patch.outputs.module }}/test/cmake_test
build-dir: __build_cmake_test__
build-dir: build_cmake_test
install: false
cmake-version: '>=3.11'
cmake-version: '>=3.20'
extra-args: |
'find_package(Boost)': -D BOOST_CI_INSTALL_TEST=ON -D CMAKE_PREFIX_PATH=${{ steps.patch.outputs.workspace_root }}/.local
'find_package(boost_url)': -D BOOST_CI_INSTALL_MODULE_TEST=ON -D CMAKE_PREFIX_PATH=${{ steps.patch.outputs.workspace_root }}/.local
Expand All @@ -216,11 +216,11 @@ jobs:
if: matrix.is-no-factor-intermediary != 'true'
with:
source-dir: .
build-dir: __build_cmake_root__
build-dir: build_cmake_root
build-target: tests
run-tests: true
install: false
cmake-version: '>=3.11'
cmake-version: '>=3.20'
extra-args: |
-D BOOST_SRC_DIR="../boost-root"
-D BOOST_URL_DISABLE_THREADS=${{ ( matrix.no-threads && 'ON' ) || 'OFF' }}
Expand All @@ -246,8 +246,11 @@ jobs:
cxxstd: ${{ ( matrix.is-latest && ((matrix.cxxstd && format('{0},latest', matrix.cxxstd)) || 'latest' )) || matrix.cxxstd }}
address-model: ${{ (matrix.x86 && '32') || '64' }}
asan: ${{ matrix.asan }}
ubsan: ${{ matrix.ubsan }}
ubsan: ${{ matrix.ubsan || matrix.integersan }}
tsan: ${{ matrix.tsan }}
# integer-sanitizer is passed directly as flags
ccflags: ${{ (matrix.integersan && '-fsanitize=integer -fno-sanitize=unsigned-integer-overflow -fno-sanitize-recover=integer -fno-omit-frame-pointer') || '' }}
cxxflags: ${{ (matrix.integersan && '-fsanitize=integer -fno-sanitize=unsigned-integer-overflow -fno-sanitize-recover=integer -fno-omit-frame-pointer') || '' }}
shared: ${{ matrix.shared }}
coverage: ${{ matrix.coverage }}
define: ${{ (matrix.no-threads && 'BOOST_URL_DISABLE_THREADS') || '' }}
Expand All @@ -258,7 +261,7 @@ jobs:
if: matrix.time-trace
with:
source-dir: ../boost-root/libs/url
build-dir: ../boost-root/__build_cmake__
build-dir: ../boost-root/build_cmake
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Codecov
Expand All @@ -273,10 +276,10 @@ jobs:
elif command -v "gcov-${{ steps.setup-cpp.outputs.version-major }}" &> /dev/null; then
gcov_tool="gcov-${{ steps.setup-cpp.outputs.version-major }}"
fi
lcov -c -q -o "../boost-root/__build_cmake__/coverage.info" -d "../boost-root/__build_cmake__" --include "$(pwd)/../boost-root/libs/${{steps.patch.outputs.module}}/*" --gcov-tool "$gcov_tool"
lcov -c -q -o "../boost-root/build_cmake/coverage.info" -d "../boost-root/build_cmake" --include "$(pwd)/../boost-root/libs/${{steps.patch.outputs.module}}/*" --gcov-tool "$gcov_tool"

# Upload to codecov
bash <(curl -s https://codecov.io/bash) -f "../boost-root/__build_cmake__/coverage.info"
bash <(curl -s https://codecov.io/bash) -f "../boost-root/build_cmake/coverage.info"

# Summary
echo "# Coverage" >> $GITHUB_STEP_SUMMARY
Expand Down
3 changes: 2 additions & 1 deletion include/boost/url/detail/encode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ re_encode_unsafe(
detail::hexdigs[opt.lower_case];
auto const encode = [end, hex](
char*& dest,
unsigned char c) noexcept
char c0) noexcept
{
auto c = static_cast<unsigned char>(c0);
ignore_unused(end);
*dest++ = '%';
BOOST_ASSERT(dest != end);
Expand Down
3 changes: 2 additions & 1 deletion include/boost/url/detail/url_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ struct BOOST_URL_DECL url_impl : parts_base
pct_string_view pct_get(int, int) const noexcept;
void set_size(int, std::size_t) noexcept;
void split(int, std::size_t) noexcept;
void adjust(int, int, std::size_t) noexcept;
void adjust_right(int first, int last, std::size_t n) noexcept;
void adjust_left(int first, int last, std::size_t n) noexcept;
void collapse(int, int, std::size_t) noexcept;

void apply_scheme(core::string_view) noexcept;
Expand Down
12 changes: 10 additions & 2 deletions include/boost/url/grammar/lut_chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ class lut_chars
unsigned char ch) noexcept
{
return ch == 255
? construct(ch, pred(ch))
: construct(ch, pred(ch)) +
? construct(ch, pred(static_cast<char>(ch)))
: construct(ch, pred(static_cast<char>(ch))) +
construct(pred, ch + 1);
}

Expand Down Expand Up @@ -257,6 +257,14 @@ class lut_chars
bool
operator()(
unsigned char ch) const noexcept
{
return operator()(static_cast<char>(ch));
}

/// @copydoc operator()(unsigned char) const
constexpr
bool
operator()(char ch) const noexcept
{
return mask_[lo(ch)] & hi(ch);
}
Expand Down
15 changes: 14 additions & 1 deletion src/detail/url_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ split(
// add n to [first, last]
void
url_impl::
adjust(
adjust_right(
int first,
int last,
std::size_t n) noexcept
Expand All @@ -289,6 +289,19 @@ adjust(
offset_[i] += n;
}

// remove n from [first, last]
void
url_impl::
adjust_left(
int first,
int last,
std::size_t n) noexcept
{
for(int i = first;
i <= last; ++i)
offset_[i] -= n;
}

// set [first, last) offset
void
url_impl::
Expand Down
15 changes: 7 additions & 8 deletions src/url_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ remove_scheme()
// (po and qo are invalidated)
if (need_resize)
{
impl_.adjust(id_user, id_end, 0 - sn);
impl_.adjust_left(id_user, id_end, sn);
}
else
{
impl_.adjust(id_user, id_path, 0 - sn);
impl_.adjust(id_query, id_end, 0 - sn + 2 * cn);
impl_.adjust_left(id_user, id_path, sn);
impl_.adjust_left(id_query, id_end, sn - 2 * cn);
}
if (encode_colon)
{
Expand Down Expand Up @@ -304,8 +304,8 @@ set_encoded_authority(
dest[n - 1] = '/';
impl_.apply_authority(a);
if(need_slash)
impl_.adjust(
id_query, id_end, 1);
impl_.adjust_right(
id_query, id_end, 1);
return *this;
}

Expand Down Expand Up @@ -2023,7 +2023,7 @@ resize_impl(
impl_.collapse(first, last,
impl_.offset(last) + n);
// shift (last, end) right
impl_.adjust(last, id_end, n);
impl_.adjust_right(last, id_end, n);
s_[size()] = '\0';
return s_ + impl_.offset(first);
}
Expand Down Expand Up @@ -2063,8 +2063,7 @@ shrink_impl(
impl_.collapse(first, last,
impl_.offset(last) - n);
// shift (last, end) left
impl_.adjust(
last, id_end, 0 - n);
impl_.adjust_left(last, id_end, n);
s_[size()] = '\0';
return s_ + impl_.offset(first);
}
Expand Down
9 changes: 3 additions & 6 deletions test/unit/test_rule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ template<class F>
void
for_each_char(F const& f)
{
unsigned char u = 0;
do
for (int i = 0; i < 256; ++i)
{
f(static_cast<
char>(u));
f(static_cast<char>(i));
}
while(++u != 0);
}

template<class CharSet>
Expand Down Expand Up @@ -60,7 +57,7 @@ test_char_set(
for_each_char(
[&cs](char c)
{
if(cs(0) || ! cs(c))
if(cs(static_cast<unsigned char>(0)) || ! cs(c))
{
if(cs(c))
{
Expand Down
Loading