Skip to content

Commit

Permalink
Merge pull request #76 from PJK/pk/fix-str-parser-example
Browse files Browse the repository at this point in the history
Enable ASan by default in debug mode; sligthly nicer fix for #67
  • Loading branch information
PJK authored Jan 27, 2019
2 parents b9c45ea + 0fcd23a commit 9f2d03b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
14 changes: 10 additions & 4 deletions .travis-qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ if [ "${ARCH}" = "arm" ]; then
arm-linux-gnueabihf-gcc-4.6 -v

# Crosscompile CMocka
pushd $HOME
pushd ${HOME}
git clone git://git.cryptomilk.org/projects/cmocka.git
mkdir cmocka_build && cd cmocka_build
cmake ../cmocka \
Expand All @@ -86,7 +86,7 @@ if [ "${ARCH}" = "arm" ]; then
popd

# Crosscompile libcbor
cmake $SOURCE \
cmake ${SOURCE} \
-DCBOR_CUSTOM_ALLOC=ON \
-DCMAKE_BUILD_TYPE=Debug \
-DWITH_TESTS=ON \
Expand All @@ -100,7 +100,7 @@ if [ "${ARCH}" = "arm" ]; then
else
# Proceed as normal
gem install coveralls-lcov
pushd $HOME
pushd ${HOME}
git clone git://git.cryptomilk.org/projects/cmocka.git
mkdir cmocka_build && cd cmocka_build
cmake ../cmocka
Expand All @@ -113,7 +113,13 @@ else
echo "Running tests"
cppcheck . --error-exitcode=1 --suppressions cppcheck_suppressions.txt --force

cmake . -DCBOR_CUSTOM_ALLOC=ON -DCMAKE_BUILD_TYPE=Debug -DWITH_TESTS=ON -DCMAKE_PREFIX_PATH=$HOME/usr/local
cmake \
-DCBOR_CUSTOM_ALLOC=ON \
-DCMAKE_BUILD_TYPE=Debug \
-DSANITIZE=OFF \
-DWITH_TESTS=ON \
-DCMAKE_PREFIX_PATH=${HOME}/usr/local \
.
make VERBOSE=1

ctest -VV
Expand Down
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ matrix:
- lcov
- cmake
- cmake-data
env: CC="clang-3.6" CXX="clang++-3.6"
- compiler: gcc
- compiler: gcc-6
addons:
apt:
sources:
Expand All @@ -35,7 +34,6 @@ matrix:
- lcov
- cmake
- cmake-data
env: CC="gcc-6" CXX="g++-6"
# Temporarily disabled due to slow performance and problems with Raspbian
# chroot (https://travis-ci.org/PJK/libcbor/jobs/281748138)
# - env: ARCH=arm
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if(PRINT_FUZZ)
add_definitions(-DPRINT_FUZZ)
endif(PRINT_FUZZ)

option(SANITIZE "Enable ASan & a few compatible sanitizers in Debug mode" ON)

set(CPACK_GENERATOR "DEB" "TGZ" "RPM")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
Expand All @@ -72,7 +73,11 @@ else()
set(CBOR_RESTRICT_SPECIFIER "restrict")

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -Wall -pedantic -g -ggdb -DDEBUG=true")
set(CMAKE_C_FLAGS_RELEASE "-O3 -flto -Wall -pedantic -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -flto -Wall -pedantic -DNDEBUG")

if(SANITIZE)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined -fsanitize=address -fsanitize=bounds -fsanitize=alignment")
endif()
endif()

set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-g")
Expand Down
9 changes: 1 addition & 8 deletions examples/streaming_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ bool key_found = false;
void find_string(void * _ctx, cbor_data buffer, size_t len)
{
if (key_found) {
char *tmp = calloc(1, len + 1);
if (!tmp) {
fprintf(stderr, "calloc failed\n");
exit(1);
}
memcpy(tmp, buffer, len);
printf("Found the value: %s\n", tmp);
free(tmp);
printf("Found the value: %.*s\n", (int) len, buffer);
key_found = false;
} else if (len == strlen(key)) {
key_found = (memcmp(key, buffer, len) == 0);
Expand Down

0 comments on commit 9f2d03b

Please sign in to comment.