From f27503509e7a0f6e43ba433f26983b22ba11060d Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Fri, 12 Jun 2026 00:29:52 -0700 Subject: [PATCH] Fix GCC truncation warnings in Python bindings errors.h Widen mju_error_msg buffer from 1024 to 2048 and replace strncpy with snprintf to avoid -Wformat-truncation and -Wstringop-truncation. PiperOrigin-RevId: 930982013 Change-Id: I0fcd726e5ed1ad28594bd4ef55b8b1ae72020043 --- python/mujoco/errors.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/mujoco/errors.h b/python/mujoco/errors.h index 0f63f55d..528ebd15 100644 --- a/python/mujoco/errors.h +++ b/python/mujoco/errors.h @@ -105,7 +105,7 @@ class ErrorBase : public pybind11::builtin_exception { // Instead, we call setjmp before entering MuJoCo, and do a longjmp from // mju_user_error back to C++ to throw an exception. static thread_local std::jmp_buf mju_error_jmp_buf; -static thread_local std::array mju_error_msg{0}; +static thread_local std::array mju_error_msg{0}; // The handler to forward non-error messages to. Set by WrapFunc before each // call into MuJoCo C code, pointing to either the previously installed TLS @@ -126,8 +126,8 @@ static inline void MjErrorHandler(const mjLogMessage* msg) { std::snprintf(mju_error_msg.data(), mju_error_msg.size(), "%s: %s", msg->func, msg->subject); } else { - std::strncpy(mju_error_msg.data(), msg->subject, mju_error_msg.size() - 1); - mju_error_msg.data()[mju_error_msg.size() - 1] = '\0'; + std::snprintf(mju_error_msg.data(), mju_error_msg.size(), "%s", + msg->subject); } std::longjmp(mju_error_jmp_buf, 1); }