4.2 backport: Fix: crash displaying negative numbers in WM_cursor_time
Displaying negative numbers would attempt to read from a negati array index on systems that don't support RGBA cursors. Resolving by making the value absolute before displaying. Back ported: - 747ab523c33687dfd7b50309e4e4250c733d70a4 - f62422884bf35b3c6440652a1ac50f9445419978 Pull Request: https://projects.blender.org/blender/blender/pulls/143011
This commit is contained in:
committed by
Philipp Oeser
parent
44dc92bed6
commit
cf4c65d8d6
@@ -344,7 +344,7 @@ bool wm_cursor_arrow_move(wmWindow *win, const wmEvent *event)
|
||||
return false;
|
||||
}
|
||||
|
||||
void WM_cursor_time(wmWindow *win, int nr)
|
||||
void WM_cursor_time(wmWindow *win, const int nr)
|
||||
{
|
||||
/* 10 8x8 digits. */
|
||||
const char number_bitmaps[10][8] = {
|
||||
@@ -366,18 +366,24 @@ void WM_cursor_time(wmWindow *win, int nr)
|
||||
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.
|
||||
* NOTE: Use of unsigned here to allow negation when `nr` is `std::numeric_limits<int>::min()`
|
||||
* which *can't* be negated. */
|
||||
uint32_t nr_abs = nr >= 0 ? uint32_t(nr) : -uint32_t(nr);
|
||||
|
||||
memset(&mask, 0xFF, sizeof(mask));
|
||||
|
||||
/* Print number bottom right justified. */
|
||||
for (int idx = 3; nr && idx >= 0; idx--) {
|
||||
const char *digit = number_bitmaps[nr % 10];
|
||||
for (int idx = 3; nr_abs && idx >= 0; idx--) {
|
||||
const char *digit = number_bitmaps[nr_abs % 10];
|
||||
int x = idx % 2;
|
||||
int y = idx / 2;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
bitmap[i + y * 8][x] = digit[i];
|
||||
}
|
||||
nr /= 10;
|
||||
nr_abs /= 10;
|
||||
}
|
||||
|
||||
window_set_custom_cursor(win, mask, bitmap, 7, 7);
|
||||
|
||||
Reference in New Issue
Block a user