Ensure that all functions that follow the SDL_GetStringRule return temporary memory

This commit is contained in:
Sam Lantinga
2024-07-19 09:50:54 -07:00
parent fd9fe1bb7b
commit 68322ac851
12 changed files with 15 additions and 36 deletions

View File

@@ -88,7 +88,6 @@ SDL_COMPILE_TIME_ASSERT(SDL_expand_byte_10_size, SDL_arraysize(SDL_expand_byte_1
/* Helper functions */
// This doesn't need SDL_FreeLater since it returns string literals.
#define CASE(X) \
case X: \
return #X;

View File

@@ -515,11 +515,10 @@ int SDL_GetNumVideoDrivers(void)
return SDL_arraysize(bootstrap) - 1;
}
// this returns string literals, so there's no need to use SDL_FreeLater.
const char *SDL_GetVideoDriver(int index)
{
if (index >= 0 && index < SDL_GetNumVideoDrivers()) {
return bootstrap[index]->name;
return SDL_CreateTemporaryString(bootstrap[index]->name);
}
return NULL;
}
@@ -657,14 +656,13 @@ pre_driver_error:
return -1;
}
// this returns string literals, so there's no need to use SDL_FreeLater.
const char *SDL_GetCurrentVideoDriver(void)
{
if (!_this) {
SDL_UninitializedVideo();
return NULL;
}
return _this->name;
return SDL_CreateTemporaryString(_this->name);
}
SDL_VideoDevice *SDL_GetVideoDevice(void)