Skip to content

Commit

Permalink
Merge pull request #255 from christian-rauch/asan_cxx
Browse files Browse the repository at this point in the history
enable ASan for C++
  • Loading branch information
christian-rauch authored Sep 8, 2022
2 parents 08e067d + 64a9888 commit e5e2341
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(ASAN "Use AddressSanitizer for debug builds to detect memory issues" OFF)

if (ASAN)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} \
set(ASAN_FLAGS "\
-fsanitize=address \
-fsanitize=bool \
-fsanitize=bounds \
Expand All @@ -24,6 +24,8 @@ if (ASAN)
-fsanitize=leak \
-fsanitize=object-size \
")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ASAN_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ASAN_FLAGS}")
endif()

# Set a default build type if none was specified
Expand Down
9 changes: 5 additions & 4 deletions example/opencv_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ int main(int argc, char *argv[])
getopt_t *getopt = getopt_create();

getopt_add_bool(getopt, 'h', "help", 0, "Show this help");
getopt_add_int(getopt, 'c', "camera", "0", "camera ID");
getopt_add_bool(getopt, 'd', "debug", 0, "Enable debugging output (slow)");
getopt_add_bool(getopt, 'q', "quiet", 0, "Reduce output");
getopt_add_string(getopt, 'f', "family", "tag36h11", "Tag family to use");
Expand All @@ -68,12 +69,12 @@ int main(int argc, char *argv[])
}

cout << "Enabling video capture" << endl;

TickMeter meter;
meter.start();

// Initialize camera
VideoCapture cap(0);
VideoCapture cap(getopt_get_int(getopt, "camera"));
if (!cap.isOpened()) {
cerr << "Couldn't open video capture device" << endl;
return -1;
Expand Down Expand Up @@ -111,7 +112,7 @@ int main(int argc, char *argv[])
printf("Unable to add family to detector due to insufficient memory to allocate the tag-family decoder with the default maximum hamming value of 2. Try choosing an alternative tag family.\n");
exit(-1);
}

td->quad_decimate = getopt_get_double(getopt, "decimate");
td->quad_sigma = getopt_get_double(getopt, "blur");
td->nthreads = getopt_get_int(getopt, "threads");
Expand All @@ -120,7 +121,7 @@ int main(int argc, char *argv[])

float frame_counter = 0.0f;
meter.stop();
cout << "Detector " << famname << " initialized in "
cout << "Detector " << famname << " initialized in "
<< std::fixed << std::setprecision(3) << meter.getTimeSec() << " seconds" << endl;
#if CV_MAJOR_VERSION > 3
cout << " " << cap.get(CAP_PROP_FRAME_WIDTH ) << "x" <<
Expand Down

0 comments on commit e5e2341

Please sign in to comment.