5683: Fix accesses to vector with index -1 by adding static button IDs r=def- a=Robyt3

See https://github.com/ddnet/ddnet/issues/5675#issuecomment-1200141378. Though I can't reproduce the UBSAN error with my compiler.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
bors[bot] 2022-07-31 17:08:19 +00:00 committed by GitHub
commit 9df5a74891
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1272,7 +1272,8 @@ int CEditor::PopupSelectImage(CEditor *pEditor, CUIRect View, void *pContext)
if(i == -1)
{
if(pEditor->DoButton_MenuItem(&pEditor->m_Map.m_vpImages[i], "None", i == g_SelectImageCurrent, &Button))
static int s_NoneButton = 0;
if(pEditor->DoButton_MenuItem(&s_NoneButton, "None", i == g_SelectImageCurrent, &Button))
g_SelectImageSelected = -1;
}
else
@ -1374,12 +1375,10 @@ int CEditor::PopupSelectSound(CEditor *pEditor, CUIRect View, void *pContext)
CUIRect Button;
ButtonBar.HSplitTop(14.0f, &Button, &ButtonBar);
//if(pEditor->UI()->MouseInside(&Button))
// ShowSound = i;
if(i == -1)
{
if(pEditor->DoButton_MenuItem(&pEditor->m_Map.m_vpSounds[i], "None", i == g_SelectSoundCurrent, &Button))
static int s_NoneButton = 0;
if(pEditor->DoButton_MenuItem(&s_NoneButton, "None", i == g_SelectSoundCurrent, &Button))
g_SelectSoundSelected = -1;
}
else