Simple Directmedia Layer

Check return value of SDL_small_alloc()

Fixes https://github.com/libsdl-org/SDL/issues/8959

+22 -55
+3
src/SDL_log.c
··· 696 696 #endif // !defined(SDL_PLATFORM_GDK) 697 697 length = SDL_strlen(GetLogPriorityPrefix(priority)) + SDL_strlen(message) + 1 + 1 + 1; 698 698 output = SDL_small_alloc(char, length, &isstack); 699 + if (!output) { 700 + return; 701 + } 699 702 (void)SDL_snprintf(output, length, "%s%s\r\n", GetLogPriorityPrefix(priority), message); 700 703 tstr = WIN_UTF8ToString(output); 701 704
+1 -2
src/render/SDL_render.c
··· 3578 3578 bool isstack1; 3579 3579 bool isstack2; 3580 3580 float *xy = SDL_small_alloc(float, 4 * 2 * count, &isstack1); 3581 - int *indices = SDL_small_alloc(int, 3582 - (4) * 3 * (count - 1) + (2) * 3 * (count), &isstack2); 3581 + int *indices = SDL_small_alloc(int, (4) * 3 * (count - 1) + (2) * 3 * (count), &isstack2); 3583 3582 3584 3583 if (xy && indices) { 3585 3584 int i;
+1 -14
src/render/opengl/SDL_render_gl.c
··· 1497 1497 1498 1498 // Flip the rows to be top-down if necessary 1499 1499 if (!renderer->target) { 1500 - bool isstack; 1501 - int length = rect->w * SDL_BYTESPERPIXEL(format); 1502 - Uint8 *src = (Uint8 *)surface->pixels + (rect->h - 1) * surface->pitch; 1503 - Uint8 *dst = (Uint8 *)surface->pixels; 1504 - Uint8 *tmp = SDL_small_alloc(Uint8, length, &isstack); 1505 - int rows = rect->h / 2; 1506 - while (rows--) { 1507 - SDL_memcpy(tmp, dst, length); 1508 - SDL_memcpy(dst, src, length); 1509 - SDL_memcpy(src, tmp, length); 1510 - dst += surface->pitch; 1511 - src -= surface->pitch; 1512 - } 1513 - SDL_small_free(tmp, isstack); 1500 + SDL_FlipSurface(surface, SDL_FLIP_VERTICAL); 1514 1501 } 1515 1502 return surface; 1516 1503 }
+5 -9
src/render/opengl/SDL_shaders_gl.c
··· 348 348 349 349 ctx->glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); 350 350 info = SDL_small_alloc(char, length + 1, &isstack); 351 - ctx->glGetInfoLogARB(shader, length, NULL, info); 352 - SDL_LogError(SDL_LOG_CATEGORY_RENDER, 353 - "Failed to compile shader:\n%s%s\n%s", defines, source, info); 354 - #ifdef DEBUG_SHADERS 355 - fprintf(stderr, 356 - "Failed to compile shader:\n%s%s\n%s", defines, source, info); 357 - #endif 358 - SDL_small_free(info, isstack); 359 - 351 + if (info) { 352 + ctx->glGetInfoLogARB(shader, length, NULL, info); 353 + SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Failed to compile shader:\n%s%s\n%s", defines, source, info); 354 + SDL_small_free(info, isstack); 355 + } 360 356 return false; 361 357 } else { 362 358 return true;
+1 -14
src/render/opengles2/SDL_render_gles2.c
··· 2014 2014 2015 2015 // Flip the rows to be top-down if necessary 2016 2016 if (!renderer->target) { 2017 - bool isstack; 2018 - int length = rect->w * SDL_BYTESPERPIXEL(format); 2019 - Uint8 *src = (Uint8 *)surface->pixels + (rect->h - 1) * surface->pitch; 2020 - Uint8 *dst = (Uint8 *)surface->pixels; 2021 - Uint8 *tmp = SDL_small_alloc(Uint8, length, &isstack); 2022 - int rows = rect->h / 2; 2023 - while (rows--) { 2024 - SDL_memcpy(tmp, dst, length); 2025 - SDL_memcpy(dst, src, length); 2026 - SDL_memcpy(src, tmp, length); 2027 - dst += surface->pitch; 2028 - src -= surface->pitch; 2029 - } 2030 - SDL_small_free(tmp, isstack); 2017 + SDL_FlipSurface(surface, SDL_FLIP_VERTICAL); 2031 2018 } 2032 2019 return surface; 2033 2020 }
+1 -15
src/render/vitagxm/SDL_render_vita_gxm.c
··· 1103 1103 read_pixels(rect->x, y, rect->w, rect->h, surface->pixels); 1104 1104 1105 1105 // Flip the rows to be top-down if necessary 1106 - 1107 1106 if (!renderer->target) { 1108 - bool isstack; 1109 - int length = rect->w * SDL_BYTESPERPIXEL(format); 1110 - Uint8 *src = (Uint8 *)surface->pixels + (rect->h - 1) * surface->pitch; 1111 - Uint8 *dst = (Uint8 *)surface->pixels; 1112 - Uint8 *tmp = SDL_small_alloc(Uint8, length, &isstack); 1113 - int rows = rect->h / 2; 1114 - while (rows--) { 1115 - SDL_memcpy(tmp, dst, length); 1116 - SDL_memcpy(dst, src, length); 1117 - SDL_memcpy(src, tmp, length); 1118 - dst += surface->pitch; 1119 - src -= surface->pitch; 1120 - } 1121 - SDL_small_free(tmp, isstack); 1107 + SDL_FlipSurface(surface, SDL_FLIP_VERTICAL); 1122 1108 } 1123 1109 return surface; 1124 1110 }
+6
src/video/SDL_surface.c
··· 1786 1786 bpp = SDL_BYTESPERPIXEL(surface->format); 1787 1787 row = (Uint8 *)surface->pixels; 1788 1788 tmp = SDL_small_alloc(Uint8, surface->pitch, &isstack); 1789 + if (!tmp) { 1790 + return false; 1791 + } 1789 1792 for (i = surface->h; i--; ) { 1790 1793 a = row; 1791 1794 b = a + (surface->w - 1) * bpp; ··· 1815 1818 a = (Uint8 *)surface->pixels; 1816 1819 b = a + (surface->h - 1) * surface->pitch; 1817 1820 tmp = SDL_small_alloc(Uint8, surface->pitch, &isstack); 1821 + if (!tmp) { 1822 + return false; 1823 + } 1818 1824 for (i = surface->h / 2; i--; ) { 1819 1825 SDL_memcpy(tmp, a, surface->pitch); 1820 1826 SDL_memcpy(a, b, surface->pitch);
+1 -1
src/video/windows/SDL_windowsevents.c
··· 1779 1779 UINT i, num_inputs = LOWORD(wParam); 1780 1780 bool isstack; 1781 1781 PTOUCHINPUT inputs = SDL_small_alloc(TOUCHINPUT, num_inputs, &isstack); 1782 - if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) { 1782 + if (inputs && data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) { 1783 1783 RECT rect; 1784 1784 float x, y; 1785 1785
+3
src/video/windows/SDL_windowswindow.c
··· 841 841 mask_len = (icon->h * (icon->w + 7) / 8); 842 842 icon_len = sizeof(BITMAPINFOHEADER) + icon->h * icon->w * sizeof(Uint32) + mask_len; 843 843 icon_bmp = SDL_small_alloc(BYTE, icon_len, &isstack); 844 + if (!icon_bmp) { 845 + return false; 846 + } 844 847 845 848 // Write the BITMAPINFO header 846 849 bmi = (BITMAPINFOHEADER *)icon_bmp;