Fix: crash displaying negative numbers in WM_cursor_time

Displaying negative numbers would attempt to read from a negative
array index on systems that don't support RGBA cursors.
Resolving by making the value absolute before displaying.
This commit is contained in:
Campbell Barton
2025-07-15 14:33:50 +10:00
parent 3a55348492
commit 747ab523c3

View File

@@ -548,6 +548,7 @@ bool wm_cursor_arrow_move(wmWindow *win, const wmEvent *event)
static bool wm_cursor_time_large(wmWindow *win, int nr)
{
BLI_assert(nr >= 0);
/* 10 16x16 digits. */
const uchar number_bitmaps[][32] = {
{0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x1f, 0x1c, 0x38, 0x0c, 0x30, 0x0c,
@@ -614,6 +615,7 @@ static bool wm_cursor_time_large(wmWindow *win, int nr)
static void wm_cursor_time_small(wmWindow *win, int nr)
{
BLI_assert(nr >= 0);
/* 10 8x8 digits. */
const char number_bitmaps[10][8] = {
{0, 56, 68, 68, 68, 68, 68, 56},
@@ -785,6 +787,11 @@ void WM_cursor_time(wmWindow *win, int nr)
if (win->lastcursor == 0) {
win->lastcursor = win->cursor;
}
/* Negative numbers not supported by #wm_cursor_time_large & #wm_cursor_time_small.
* Make absolute to show *something* although in typical usage this shouldn't be negative. */
if (UNLIKELY(nr < 0)) {
nr = -nr;
}
/* Use `U.ui_scale` instead of `UI_SCALE_FAC` here to ignore HiDPI/Retina scaling. */
if (WM_capabilities_flag() & WM_CAPABILITY_CURSOR_RGBA) {