Static analysis fix: division by zero.

main
Ryan C. Gordon 2014-03-20 11:14:44 -04:00
parent b659c70080
commit 415675bef0
2 changed files with 9 additions and 2 deletions

View File

@ -404,6 +404,10 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int
if (!format) { if (!format) {
format = renderer->info.texture_formats[0]; format = renderer->info.texture_formats[0];
} }
if (SDL_BYTESPERPIXEL(format) == 0) {
SDL_SetError("Invalid texture format");
return NULL;
}
if (SDL_ISPIXELFORMAT_INDEXED(format)) { if (SDL_ISPIXELFORMAT_INDEXED(format)) {
SDL_SetError("Palettized textures are not supported"); SDL_SetError("Palettized textures are not supported");
return NULL; return NULL;

View File

@ -24,6 +24,7 @@
#include "SDL_hints.h" #include "SDL_hints.h"
#include "SDL_log.h" #include "SDL_log.h"
#include "SDL_assert.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"
#include "../SDL_sysrender.h" #include "../SDL_sysrender.h"
#include "SDL_shaders_gl.h" #include "SDL_shaders_gl.h"
@ -798,14 +799,16 @@ GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
{ {
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
GL_TextureData *data = (GL_TextureData *) texture->driverdata; GL_TextureData *data = (GL_TextureData *) texture->driverdata;
const int texturebpp = SDL_BYTESPERPIXEL(texture->format);
SDL_assert(texturebpp != 0); /* otherwise, division by zero later. */
GL_ActivateRenderer(renderer); GL_ActivateRenderer(renderer);
renderdata->glEnable(data->type); renderdata->glEnable(data->type);
renderdata->glBindTexture(data->type, data->texture); renderdata->glBindTexture(data->type, data->texture);
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / texturebpp));
(pitch / SDL_BYTESPERPIXEL(texture->format)));
renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
rect->h, data->format, data->formattype, rect->h, data->format, data->formattype,
pixels); pixels);