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

Enable sanitizers with Noa #725

Merged
merged 6 commits into from
Feb 10, 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
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ jobs:
# cc: gcc
# cxx: g++
- os: windows-latest
# TODO: Enable sanitizers

# Sanitizers
- os: ubuntu-latest
cc: clang
cxx: clang++
type: static
options: -DJSONBINPACK_ADDRESS_SANITIZER:BOOL=ON
- os: ubuntu-latest
cc: clang
cxx: clang++
type: static
options: -DJSONBINPACK_UNDEFINED_SANITIZER:BOOL=ON

runs-on: ${{ matrix.platform.os }}
env:
Expand Down Expand Up @@ -64,6 +75,7 @@ jobs:
-DJSONBINPACK_DOCS:BOOL=OFF
-DBUILD_SHARED_LIBS:BOOL=OFF
-DCMAKE_COMPILE_WARNING_AS_ERROR:BOOL=ON
${{ matrix.platform.options }}
- run: cmake --build ./build --config Release --target clang_format_test
- run: cmake --build ./build --config Release --parallel 4
- run: >
Expand Down
17 changes: 10 additions & 7 deletions src/runtime/include/sourcemeta/jsonbinpack/runtime_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,21 @@ class Decoder : private BasicDecoder<CharT, Traits> {
// We trust the encoder that the data we are seeing
// corresponds to a valid 64-bit signed integer.
return sourcemeta::jsontoolkit::JSON{static_cast<std::int64_t>(
-(static_cast<std::int64_t>(this->get_varint() *
options.multiplier)) +
closest_maximum_multiple)};
-(static_cast<std::int64_t>(
this->get_varint() *
static_cast<std::int64_t>(options.multiplier))) +
static_cast<std::int64_t>(closest_maximum_multiple))};
} else {
const std::uint64_t closest_maximum_multiple{
static_cast<std::uint32_t>(std::abs(closest_maximum)) *
options.multiplier};
// We trust the encoder that the data we are seeing
// corresponds to a valid 64-bit signed integer.
return sourcemeta::jsontoolkit::JSON{static_cast<std::int64_t>(
-(static_cast<std::int64_t>(this->get_varint() *
options.multiplier)) -
closest_maximum_multiple)};
-(static_cast<std::int64_t>(
this->get_varint() *
static_cast<std::int64_t>(options.multiplier))) -
static_cast<std::int64_t>(closest_maximum_multiple))};
}
}

Expand All @@ -153,7 +155,8 @@ class Decoder : private BasicDecoder<CharT, Traits> {
// We trust the encoder that the data we are seeing
// corresponds to a valid 64-bit signed integer.
return sourcemeta::jsontoolkit::JSON{static_cast<std::int64_t>(
this->get_varint_zigzag() * options.multiplier)};
this->get_varint_zigzag() *
static_cast<std::int64_t>(options.multiplier))};
}

/// @}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ template <typename CharT, typename Traits> class BasicDecoder {
result.reserve(length);
std::uint64_t counter = 0;
while (counter < length) {
result += this->get_byte();
result += static_cast<CharT>(this->get_byte());
counter += 1;
}

Expand Down
6 changes: 4 additions & 2 deletions src/runtime/include/sourcemeta/jsonbinpack/runtime_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class Encoder : private BasicEncoder<CharT, Traits> {
#endif
assert(is_byte(enum_maximum - enum_minimum));
this->put_byte(static_cast<std::uint8_t>(
static_cast<std::int64_t>(value / options.multiplier) - enum_minimum));
(value / static_cast<std::int64_t>(options.multiplier)) -
enum_minimum));
}

auto FLOOR_MULTIPLE_ENUM_VARINT(const sourcemeta::jsontoolkit::JSON &document,
Expand Down Expand Up @@ -128,7 +129,8 @@ class Encoder : private BasicEncoder<CharT, Traits> {
const std::int64_t value{document.to_integer()};
assert(options.multiplier > 0);
assert(std::abs(value) % options.multiplier == 0);
this->put_varint_zigzag(value / options.multiplier);
this->put_varint_zigzag(value /
static_cast<std::int64_t>(options.multiplier));
}

/// @}
Expand Down
Loading