Prevent crashes if freed objects are passed to SDL API functions

Instead of using the magic tag in the object, we'll actually keep track of valid objects

Fixes https://github.com/libsdl-org/SDL/issues/9869
Fixes https://github.com/libsdl-org/SDL/issues/9235
This commit is contained in:
Sam Lantinga
2024-06-03 04:09:28 -07:00
parent 57a15933cd
commit b0e93e4e63
28 changed files with 191 additions and 126 deletions

View File

@@ -32,4 +32,24 @@ extern void SDL_CalculateFraction(float x, int *numerator, int *denominator);
extern SDL_bool SDL_endswith(const char *string, const char *suffix);
typedef enum
{
SDL_OBJECT_TYPE_UNKNOWN,
SDL_OBJECT_TYPE_WINDOW,
SDL_OBJECT_TYPE_RENDERER,
SDL_OBJECT_TYPE_TEXTURE,
SDL_OBJECT_TYPE_JOYSTICK,
SDL_OBJECT_TYPE_GAMEPAD,
SDL_OBJECT_TYPE_HAPTIC,
SDL_OBJECT_TYPE_SENSOR,
SDL_OBJECT_TYPE_HIDAPI_DEVICE,
SDL_OBJECT_TYPE_HIDAPI_JOYSTICK,
} SDL_ObjectType;
extern Uint32 SDL_GetNextObjectID(void);
extern void SDL_SetObjectValid(void *object, SDL_ObjectType type, SDL_bool valid);
extern SDL_bool SDL_ObjectValid(void *object, SDL_ObjectType type);
extern void SDL_SetObjectsInvalid(void);
#endif /* SDL_utils_h_ */