Skip to content

Commit 10d375b

Browse files
committed
CBD-6348: [BP] clang-analyzer: Dereference of null pointer
After upgrade to clang-15 it warns that the parameter to the constructor must not be null. Change-Id: Ia474927a2b862ed854071f2b822c9a5b6e2fe8e4 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/235156 Well-Formed: Restriction Checker Tested-by: Trond Norbye <[email protected]> Reviewed-by: Faizan Alam <[email protected]> Reviewed-by: Vesko Karaganev <[email protected]>
1 parent c816303 commit 10d375b

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

engines/crash_engine/crash_engine.cc

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <string>
2121
#include <thread>
2222

23+
#include <fmt/format.h>
2324
#include <folly/lang/Assume.h>
2425
#include <memcached/config_parser.h>
2526
#include <memcached/engine.h>
@@ -71,24 +72,32 @@ class CrashEngine : public EngineIface {
7172
* means crashing it.
7273
*/
7374
cb::engine_errc initialize(const std::string&) override {
74-
std::string mode_string(getenv("MEMCACHED_CRASH_TEST"));
75+
using namespace std::string_view_literals;
76+
const auto* ptr = getenv("MEMCACHED_CRASH_TEST");
77+
if (!ptr) {
78+
fmt::print(
79+
stderr,
80+
"crash_engine::initialize: MEMCACHED_CRASH_TEST not set\n");
81+
std::_Exit(EXIT_FAILURE);
82+
}
83+
std::string_view mode_string(ptr);
7584
CrashMode mode;
76-
if (mode_string == "segfault") {
85+
if (mode_string == "segfault"sv) {
7786
mode = CrashMode::SegFault;
78-
} else if (mode_string == "std_exception") {
87+
} else if (mode_string == "std_exception"sv) {
7988
mode = CrashMode::UncaughtStdException;
80-
} else if (mode_string == "std_exception_via_std_thread") {
89+
} else if (mode_string == "std_exception_via_std_thread"sv) {
8190
mode = CrashMode::UncaughtStdExceptionViaStdThread;
82-
} else if (mode_string == "std_exception_with_trace") {
91+
} else if (mode_string == "std_exception_with_trace"sv) {
8392
mode = CrashMode::UncaughtStdExceptionWithTrace;
84-
} else if (mode_string == "unknown_exception") {
93+
} else if (mode_string == "unknown_exception"sv) {
8594
mode = CrashMode::UncaughtUnknownException;
8695
} else {
87-
fprintf(stderr,
88-
"crash_engine::initialize: could not find a valid "
89-
"CrashMode from MEMCACHED_CRASH_TEST env var ('%s')\n",
90-
mode_string.c_str());
91-
exit(1);
96+
fmt::print(stderr,
97+
"crash_engine::initialize: could not find a valid "
98+
"CrashMode from MEMCACHED_CRASH_TEST env var ({:?})\n",
99+
mode_string);
100+
exit(EXIT_FAILURE);
92101
}
93102
if (mode == CrashMode::UncaughtStdExceptionViaStdThread) {
94103
std::thread thread{[mode] { recursive_crash_function(25, mode); }};

0 commit comments

Comments
 (0)