From 8d42473ed029a27f6ba2a913007ae7d2c9d36b1a Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Thu, 11 Jun 2026 22:24:39 -0700 Subject: [PATCH] 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 --- test/fixture.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixture.h b/test/fixture.h index c6a4457b..07e23126 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -135,11 +135,11 @@ class MujocoTest : public ::testing::Test { template auto MjuErrorMessageFrom(Return (*func)(Args...)) { 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 { 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); };