Fix GCC -Wstringop-truncation in test fixture
Widen err_msg buffer in MjuErrorMessageFrom to 2048 and use snprintf instead of strncpy to avoid truncation warnings. PiperOrigin-RevId: 930932293 Change-Id: Iea43d28cf209356d66cf16be48e750e947242b14
This commit is contained in:
committed by
Copybara-Service
parent
a070535c65
commit
8d42473ed0
+2
-2
@@ -135,11 +135,11 @@ class MujocoTest : public ::testing::Test {
|
|||||||
template <typename Return, typename... Args>
|
template <typename Return, typename... Args>
|
||||||
auto MjuErrorMessageFrom(Return (*func)(Args...)) {
|
auto MjuErrorMessageFrom(Return (*func)(Args...)) {
|
||||||
thread_local std::jmp_buf current_jmp_buf;
|
thread_local std::jmp_buf current_jmp_buf;
|
||||||
thread_local char err_msg[1000];
|
thread_local char err_msg[2048];
|
||||||
|
|
||||||
auto new_error_handler = +[](const mjLogMessage* msg) -> void {
|
auto new_error_handler = +[](const mjLogMessage* msg) -> void {
|
||||||
if (msg->level != mjLOG_ERROR) return;
|
if (msg->level != mjLOG_ERROR) return;
|
||||||
std::strncpy(err_msg, msg->subject, sizeof(err_msg));
|
std::snprintf(err_msg, sizeof(err_msg), "%s", msg->subject);
|
||||||
std::longjmp(current_jmp_buf, 1);
|
std::longjmp(current_jmp_buf, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user