Skip to content

Commit

Permalink
Enable sanitizers with Noa
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Feb 9, 2024
1 parent 960fd37 commit fa07ec9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
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 @@ -63,6 +74,7 @@ jobs:
-DJSONBINPACK_WEBSITE: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
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ option(JSONBINPACK_COMPILER "Build the JSON BinPack compiler" ON)
option(JSONBINPACK_TESTS "Build the JSON BinPack tests" OFF)
option(JSONBINPACK_INSTALL "Install the JSON BinPack library" ON)
option(JSONBINPACK_WEBSITE "Build the JSON BinPack website" OFF)
option(JSONBINPACK_ADDRESS_SANITIZER "Build JSON BinPack with an address sanitizer" OFF)
option(JSONBINPACK_UNDEFINED_SANITIZER "Build JSON BinPack with an undefined behavior sanitizer" OFF)

# TODO: Generate (and test) CMake config

Expand All @@ -36,6 +38,12 @@ if(JSONBINPACK_CLI)
add_subdirectory(src/cli)
endif()

if(JSONBINPACK_ADDRESS_SANITIZER)
noa_sanitizer(TYPE address)
elseif(JSONBINPACK_UNDEFINED_SANITIZER)
noa_sanitizer(TYPE undefined)
endif()

# TODO: Get rid of Jekyll
if(JSONBINPACK_WEBSITE)
string(TOLOWER ${CMAKE_BUILD_TYPE} JSONBINPACK_BUILD_TYPE)
Expand Down
5 changes: 3 additions & 2 deletions src/encoder/include/sourcemeta/jsonbinpack/encoder_varint.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ auto varint(std::basic_ostream<CharT, Traits> &stream,
std::uint64_t accumulator = value;

while (accumulator > LEAST_SIGNIFICANT_BITS) {
stream.put(static_cast<std::uint8_t>(
stream.put(static_cast<std::basic_ostream<CharT, Traits>::char_type>(
(accumulator & LEAST_SIGNIFICANT_BITS) | MOST_SIGNIFICANT_BIT));
accumulator >>= SHIFT;
}

stream.put(static_cast<std::uint8_t>(accumulator));
stream.put(
static_cast<std::basic_ostream<CharT, Traits>::char_type>(accumulator));
return stream;
}

Expand Down

0 comments on commit fa07ec9

Please sign in to comment.