In this ternary, the true branch yields a reference to std::string. The
false branch, `nullptr` is therefore implicitly cast to an std::string.
It builds, since you can build an std::string from a pointer to a C
string, but it would crash at runtime, since constructing an std::string
from nullptr doesn't work.
Ultimately, we want to pass this to the ClockClass::origin() setter,
which takes a CStringView, so cast the true branch to CStringView. If
the condition is false, this constructs a CStringView from nullptr,
which is correct and what we want to do here.
This problem was reported by clang-tidy as a bugprone-string-constructor
[1] error ("Constructing string from nullptr is undefined behaviour").
[1] https://clang.llvm.org/extra/clang-tidy/checks/bugprone/string-constructor.html
Change-Id: Ib9c8dfa619cbd652c8284ef7c3a4ccebeb0e6fbd
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13299
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
clkCls.libCls()->setOriginIsUnixEpoch();
} else if (_mMipVersion >= 1) {
/* Custom (MIP 1+) */
- clkCls.libCls()->origin(clkCls.origin()->ns() ? *clkCls.origin()->ns() : nullptr,
+ clkCls.libCls()->origin(clkCls.origin()->ns() ?
+ static_cast<bt2c::CStringView>(*clkCls.origin()->ns()) :
+ nullptr,
clkCls.origin()->name(), clkCls.origin()->uid());
}
} else {