forked from Ports/perfect_dark
Merge pull request #114 from iamgreaser/gm/ubfix-0001
Fix a few cases of UB incl. OoB
This commit is contained in:
4 files changed
+52
No files matched your search
@@ -1952,6 +1952,9 @@ Gfx *bviewDrawNvLens(Gfx *gdl)
|
||||
s32 viewbottom = viewtop + viewheight;
|
||||
s32 brightness;
|
||||
s32 y;
|
||||
#ifdef AVOID_UB
|
||||
u32 mpindex = g_Vars.currentplayerstats->mpindex % MAX_PLAYERS;
|
||||
#endif
|
||||
|
||||
var8007f840++;
|
||||
|
||||
@@ -1973,9 +1976,15 @@ Gfx *bviewDrawNvLens(Gfx *gdl)
|
||||
skySetOverexposure(brightness, brightness, brightness);
|
||||
}
|
||||
|
||||
#ifdef AVOID_UB
|
||||
if (g_Menus[mpindex].curdialog == NULL) {
|
||||
gdl = bviewDrawMotionBlur(gdl, 0x00ff0000, 0x60);
|
||||
}
|
||||
#else
|
||||
if (g_Menus[g_Vars.currentplayerstats->mpindex].curdialog == NULL) {
|
||||
gdl = bviewDrawMotionBlur(gdl, 0x00ff0000, 0x60);
|
||||
}
|
||||
#endif
|
||||
|
||||
gDPPipeSync(gdl++);
|
||||
|
||||
@@ -2034,6 +2043,9 @@ Gfx *bviewDrawIrLens(Gfx *gdl)
|
||||
s32 viewcentrey;
|
||||
f32 viewheightf;
|
||||
s32 a0;
|
||||
#ifdef AVOID_UB
|
||||
u32 mpindex = g_Vars.currentplayerstats->mpindex % MAX_PLAYERS;
|
||||
#endif
|
||||
|
||||
#if VERSION < VERSION_NTSC_1_0
|
||||
static s32 fsscanline = 0;
|
||||
@@ -2198,9 +2210,15 @@ Gfx *bviewDrawIrLens(Gfx *gdl)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef AVOID_UB
|
||||
if (g_Menus[mpindex].curdialog == NULL) {
|
||||
gdl = bviewDrawMotionBlur(gdl, 0xff000000, 0x40);
|
||||
}
|
||||
#else
|
||||
if (g_Menus[g_Vars.currentplayerstats->mpindex].curdialog == NULL) {
|
||||
gdl = bviewDrawMotionBlur(gdl, 0xff000000, 0x40);
|
||||
}
|
||||
#endif
|
||||
|
||||
return gdl;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <ultra64.h>
|
||||
#include <string.h>
|
||||
#include "constants.h"
|
||||
#include "game/atan2f.h"
|
||||
#include "game/camera.h"
|
||||
@@ -600,6 +601,9 @@ bool camIsPosInFovAndVisibleRoom(RoomNum *rooms, struct coord *pos, f32 arg2)
|
||||
RoomNum room;
|
||||
bool hasdata = false;
|
||||
struct drawslot *thisthing;
|
||||
#ifdef AVOID_UB
|
||||
static struct drawslot dslot;
|
||||
#endif
|
||||
struct screenbox box;
|
||||
|
||||
for (i = 0, room = rooms[i]; room != -1; i++, room = rooms[i]) {
|
||||
@@ -637,5 +641,10 @@ bool camIsPosInFovAndVisibleRoom(RoomNum *rooms, struct coord *pos, f32 arg2)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef AVOID_UB
|
||||
memcpy(&dslot.box, &box, sizeof(box));
|
||||
return camIsPosInScreenBox(pos, arg2, &dslot);
|
||||
#else
|
||||
return camIsPosInScreenBox(pos, arg2, (struct drawslot *) &(((u8 *) &box)[-((uintptr_t) &(((struct drawslot *)0)->box))]));
|
||||
#endif
|
||||
}
|
||||
@@ -329,7 +329,11 @@ void gfxReplaceGbiCommands(Gfx *startgdl, Gfx *endgdl, s32 type)
|
||||
|
||||
void gfxReplaceGbiCommandsRecursively(struct roomblock *block, s32 type)
|
||||
{
|
||||
#ifndef AVOID_UB
|
||||
// Sometimes block is NULL when this is called.
|
||||
// If UBSan is being used, this will crash in this instance.
|
||||
if (block->type == ROOMBLOCKTYPE_PARENT);
|
||||
#endif
|
||||
|
||||
while (true) {
|
||||
if (!block) {
|
||||
|
||||
@@ -3411,8 +3411,14 @@ void menuClose(void)
|
||||
|
||||
void func0f0f8120(void)
|
||||
{
|
||||
#ifdef AVOID_UB
|
||||
u32 mpindex = g_MpPlayerNum % MAX_PLAYERS;
|
||||
struct menudialog *prev = g_Menus[mpindex].curdialog;
|
||||
s32 i;
|
||||
#else
|
||||
struct menudialog *prev = g_Menus[g_MpPlayerNum].curdialog;
|
||||
s32 i;
|
||||
#endif
|
||||
|
||||
if (g_MenuData.unk66e > 0) {
|
||||
for (i = g_MenuData.unk66e; i >= 0; i--) {
|
||||
@@ -3420,11 +3426,22 @@ void func0f0f8120(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef AVOID_UB
|
||||
mpindex = g_MpPlayerNum;
|
||||
if (mpindex >= MAX_PLAYERS)
|
||||
mpindex -= MAX_PLAYERS;
|
||||
if (g_Menus[mpindex].curdialog == prev) {
|
||||
while (g_Menus[mpindex].depth > 0) {
|
||||
menuPopDialog();
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (g_Menus[g_MpPlayerNum].curdialog == prev) {
|
||||
while (g_Menus[g_MpPlayerNum].depth > 0) {
|
||||
menuPopDialog();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void func0f0f820c(struct menudialogdef *dialogdef, s32 root)
|
||||
@@ -4338,7 +4355,11 @@ void dialogTick(struct menudialog *dialog, struct menuinputs *inputs, u32 tickfl
|
||||
}
|
||||
|
||||
// Apply default navigational behaviour if requested
|
||||
#ifdef AVOID_UB
|
||||
if (usedefaultbehaviour && (tickflags & MENUTICKFLAG_DIALOGISCURRENT) && !dialog->dimmed && g_Menus[g_MpPlayerNum].depth >= 1) {
|
||||
#else
|
||||
if (usedefaultbehaviour && (tickflags & MENUTICKFLAG_DIALOGISCURRENT) && !dialog->dimmed) {
|
||||
#endif
|
||||
struct menulayer *layer = &g_Menus[g_MpPlayerNum].layers[g_Menus[g_MpPlayerNum].depth - 1];
|
||||
|
||||
if (layer->numsiblings <= 1) {
|
||||
|
||||
Reference in new issue
Block a user