Skip to content

Commit e5e2341

Browse files
Merge pull request #255 from christian-rauch/asan_cxx
enable ASan for C++
2 parents 08e067d + 64a9888 commit e5e2341

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries" ON)
88
option(ASAN "Use AddressSanitizer for debug builds to detect memory issues" OFF)
99

1010
if (ASAN)
11-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} \
11+
set(ASAN_FLAGS "\
1212
-fsanitize=address \
1313
-fsanitize=bool \
1414
-fsanitize=bounds \
@@ -24,6 +24,8 @@ if (ASAN)
2424
-fsanitize=leak \
2525
-fsanitize=object-size \
2626
")
27+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ASAN_FLAGS}")
28+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ASAN_FLAGS}")
2729
endif()
2830

2931
# Set a default build type if none was specified

example/opencv_demo.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ int main(int argc, char *argv[])
5252
getopt_t *getopt = getopt_create();
5353

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

7071
cout << "Enabling video capture" << endl;
71-
72+
7273
TickMeter meter;
7374
meter.start();
7475

7576
// Initialize camera
76-
VideoCapture cap(0);
77+
VideoCapture cap(getopt_get_int(getopt, "camera"));
7778
if (!cap.isOpened()) {
7879
cerr << "Couldn't open video capture device" << endl;
7980
return -1;
@@ -111,7 +112,7 @@ int main(int argc, char *argv[])
111112
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");
112113
exit(-1);
113114
}
114-
115+
115116
td->quad_decimate = getopt_get_double(getopt, "decimate");
116117
td->quad_sigma = getopt_get_double(getopt, "blur");
117118
td->nthreads = getopt_get_int(getopt, "threads");
@@ -120,7 +121,7 @@ int main(int argc, char *argv[])
120121

121122
float frame_counter = 0.0f;
122123
meter.stop();
123-
cout << "Detector " << famname << " initialized in "
124+
cout << "Detector " << famname << " initialized in "
124125
<< std::fixed << std::setprecision(3) << meter.getTimeSec() << " seconds" << endl;
125126
#if CV_MAJOR_VERSION > 3
126127
cout << " " << cap.get(CAP_PROP_FRAME_WIDTH ) << "x" <<

0 commit comments

Comments
 (0)