diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index c3052b2de55..aa54b92adad 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -5694,12 +5694,24 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type, utf8_buf_len); } - if (BLI_str_utf8_size_or_error(event.utf8_buf) == -1) { + const int utf8_buf_len = BLI_str_utf8_size_or_error(event.utf8_buf); + if (utf8_buf_len == -1) { CLOG_ERROR(WM_LOG_EVENTS, "ghost detected an invalid unicode character '%d'", int(uchar(event.utf8_buf[0]))); event.utf8_buf[0] = '\0'; } + else { +#ifndef NDEBUG + /* Ensure callers don't accidentally treat this as a "string", + * it's not null terminated. */ + if (utf8_buf_len > 0) { + for (int i = utf8_buf_len; i < ARRAY_SIZE(event.utf8_buf); i++) { + event.utf8_buf[i] = 0xff; + } + } +#endif /* !NDEBUG */ + } } /* NOTE(@ideasman42): Setting the modifier state based on press/release