mirror of https://github.com/libsdl-org/SDL.git
Don't create surfaces with invalid pixel formats
Fixes https://github.com/libsdl-org/SDL/issues/12556
This commit is contained in:
parent
6f456da63f
commit
476e7e54cb
|
|
@ -204,6 +204,11 @@ SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormat format)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (format == SDL_PIXELFORMAT_UNKNOWN) {
|
||||||
|
SDL_InvalidParamError("format");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!SDL_CalculateSurfaceSize(format, width, height, &size, &pitch, false /* not minimal pitch */)) {
|
if (!SDL_CalculateSurfaceSize(format, width, height, &size, &pitch, false /* not minimal pitch */)) {
|
||||||
// Overflow...
|
// Overflow...
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -250,6 +255,11 @@ SDL_Surface *SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (format == SDL_PIXELFORMAT_UNKNOWN) {
|
||||||
|
SDL_InvalidParamError("format");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (pitch == 0 && !pixels) {
|
if (pitch == 0 && !pixels) {
|
||||||
// The application will fill these in later with valid values
|
// The application will fill these in later with valid values
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -313,6 +313,24 @@ static void AssertFileExist(const char *filename)
|
||||||
|
|
||||||
/* Test case functions */
|
/* Test case functions */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests creating surface with invalid format
|
||||||
|
*/
|
||||||
|
static int SDLCALL surface_testInvalidFormat(void *arg)
|
||||||
|
{
|
||||||
|
SDL_Surface *surface;
|
||||||
|
|
||||||
|
surface = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_UNKNOWN);
|
||||||
|
SDLTest_AssertCheck(surface == NULL, "Verify SDL_CreateSurface(SDL_PIXELFORMAT_UNKNOWN) returned NULL");
|
||||||
|
SDL_DestroySurface(surface);
|
||||||
|
|
||||||
|
surface = SDL_CreateSurfaceFrom(32, 32, SDL_PIXELFORMAT_UNKNOWN, NULL, 0);
|
||||||
|
SDLTest_AssertCheck(surface == NULL, "Verify SDL_CreateSurfaceFrom(SDL_PIXELFORMAT_UNKNOWN) returned NULL");
|
||||||
|
SDL_DestroySurface(surface);
|
||||||
|
|
||||||
|
return TEST_COMPLETED;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests sprite saving and loading
|
* Tests sprite saving and loading
|
||||||
*/
|
*/
|
||||||
|
|
@ -1542,6 +1560,10 @@ static int SDLCALL surface_testScale(void *arg)
|
||||||
/* ================= Test References ================== */
|
/* ================= Test References ================== */
|
||||||
|
|
||||||
/* Surface test cases */
|
/* Surface test cases */
|
||||||
|
static const SDLTest_TestCaseReference surfaceTestInvalidFormat = {
|
||||||
|
surface_testInvalidFormat, "surface_testInvalidFormat", "Tests creating surface with invalid format", TEST_ENABLED
|
||||||
|
};
|
||||||
|
|
||||||
static const SDLTest_TestCaseReference surfaceTestSaveLoadBitmap = {
|
static const SDLTest_TestCaseReference surfaceTestSaveLoadBitmap = {
|
||||||
surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED
|
surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED
|
||||||
};
|
};
|
||||||
|
|
@ -1640,6 +1662,7 @@ static const SDLTest_TestCaseReference surfaceTestScale = {
|
||||||
|
|
||||||
/* Sequence of Surface test cases */
|
/* Sequence of Surface test cases */
|
||||||
static const SDLTest_TestCaseReference *surfaceTests[] = {
|
static const SDLTest_TestCaseReference *surfaceTests[] = {
|
||||||
|
&surfaceTestInvalidFormat,
|
||||||
&surfaceTestSaveLoadBitmap,
|
&surfaceTestSaveLoadBitmap,
|
||||||
&surfaceTestBlitZeroSource,
|
&surfaceTestBlitZeroSource,
|
||||||
&surfaceTestBlit,
|
&surfaceTestBlit,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue