✨Mark bugs that involve genuine undefined behavior as UBFix#2328
✨Mark bugs that involve genuine undefined behavior as UBFix#2328AZero13 wants to merge 1 commit into
Conversation
mrgriffin
left a comment
There was a problem hiding this comment.
I'm not sure why there's a distinction between BUGFIX and UBFIX, but assuming it's for a good reason* I've pointed out some cases where I'm not sure what the UB is.
* ig it's for people that want to compile a ROM which works almost exactly the same as vanilla, but without invoking any UB? If that's the case, then the src/battle_gfx_sfx_util.c/src/trainer_pokemon_sprites.c ones wouldn't qualify. Maybe it's "people want to compile a ROM that's altered but can't invoke any UB without them violating a reasonable precondition", "reasonable" because "you can't have non-transparent pixels in the first tile's top row" is obviously not reasonable.
| s32 i; | ||
| s32 j; | ||
| #ifndef BUGFIX | ||
| #ifndef UBFIX |
| {gObjectEventPal_RubySapphireBrendan, OBJ_EVENT_PAL_TAG_RS_BRENDAN}, | ||
| {gObjectEventPal_RubySapphireMay, OBJ_EVENT_PAL_TAG_RS_MAY}, | ||
| #ifdef BUGFIX | ||
| #ifdef UBFIX |
There was a problem hiding this comment.
idk if this is really a fix for UB. Yes, it's UB if you ask for a tag that isn't in this list, but that's a precondition of the code; if "can invoke UB when you violate a precondition" is the bar for what's UB or not then every function that dereferences a pointer without a NULL check should grow UBFIX that checks for NULL and that's obviously silly.
| u32 flags; | ||
|
|
||
| #ifdef BUGFIX | ||
| #ifdef UBFIX |
There was a problem hiding this comment.
I haven't looked into it, but why's it UB for the camera to trigger ground effects?
There was a problem hiding this comment.
if the check objEvent->localId != OBJ_EVENT_ID_CAMERA is missing, the game will attempt to run the ground effects logic on the camera sprite
There was a problem hiding this comment.
During the OAM update/rendering loop, the engine checks sprite->subspriteTableNum and attempts to read from sprite->subspriteTables[4].
Because subspriteTables is NULL, this compiles to an offset reference of NULL + 4 * sizeof(void *), trying to read from memory address 0x00000010.
There was a problem hiding this comment.
afaict the only call to AddSubspritesToOamBuffer is on the else of if (!sprite->subspriteTables || sprite->subspriteMode == SUBSPRITES_OFF)? (i.e. only entered if subspriteTables != NULL && sprite->subspriteMode != SUBSPRITES_OFF)
I thought the goal was to make something like the PC port easier to do by providing a compile-time flag to enable null-pointer checks Gamefreak didn't do because dereferencing a null pointer just reads the last instruction read from the firmware, and that happens not to crash the game in those instances in the vanilla game. |
|
Addressed! |
55611e5 to
20a1d8e
Compare
|
✨ |
The objEvent->localId != OBJ_EVENT_ID_CAMERA counts because this results in a null dereference, which is fine for vanilla I guess, but still wrong.