WM: ensure wmEvent::utf8_buf isn't treated as a null terminated string

In debug mode, fill remaining bytes so functionality that relies
on null termination will alert developers to incorrect use early on.
This commit is contained in:
Campbell Barton
2023-09-20 09:44:28 +10:00
parent 264c3e7bd7
commit 53cbdaaa8b

View File

@@ -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