Fix invalid XR action map indices after alloc

Although the relevant structs (wmXrRuntime/XrActionMap/
XrActionMapItem) are zero-allocated, the selected and active action
map indices need to be initialized to -1 to prevent potential
out-of-bounds list access.
This commit is contained in:
Peter Kim 2021-08-06 17:55:00 +09:00
parent d98791a106
commit 151eed752b
2 changed files with 3 additions and 0 deletions

@ -149,6 +149,7 @@ bool wm_xr_events_handle(wmWindowManager *wm)
wmXrRuntimeData *wm_xr_runtime_data_create(void)
{
wmXrRuntimeData *runtime = MEM_callocN(sizeof(*runtime), __func__);
runtime->actactionmap = runtime->selactionmap = -1;
return runtime;
}

@ -256,6 +256,7 @@ XrActionMapItem *WM_xr_actionmap_item_new(XrActionMap *actionmap,
if (ami_prev) {
WM_xr_actionmap_item_ensure_unique(actionmap, ami);
}
ami->selbinding = -1;
BLI_addtail(&actionmap->items, ami);
@ -398,6 +399,7 @@ XrActionMap *WM_xr_actionmap_new(wmXrRuntimeData *runtime, const char *name, boo
if (am_prev) {
WM_xr_actionmap_ensure_unique(runtime, am);
}
am->selitem = -1;
BLI_addtail(&runtime->actionmaps, am);