From 1f77d0b35676bd416ac7b5b4c01829925d543edc Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 31 Jul 2023 14:48:53 +0200 Subject: [PATCH] [rdtk] assert arguments --- rdtk/librdtk/rdtk_button.c | 25 ++++++++++++++++--------- rdtk/librdtk/rdtk_engine.c | 6 +++--- rdtk/librdtk/rdtk_label.c | 17 ++++++++++------- rdtk/librdtk/rdtk_nine_patch.c | 31 +++++++++++++++++++++---------- rdtk/librdtk/rdtk_surface.c | 5 +++++ rdtk/librdtk/rdtk_text_field.c | 14 ++++++++++++-- 6 files changed, 67 insertions(+), 31 deletions(-) diff --git a/rdtk/librdtk/rdtk_button.c b/rdtk/librdtk/rdtk_button.c index 2c0f09a78..797193794 100644 --- a/rdtk/librdtk/rdtk_button.c +++ b/rdtk/librdtk/rdtk_button.c @@ -16,6 +16,8 @@ * limitations under the License. */ +#include + #include #include "rdtk_font.h" @@ -31,14 +33,14 @@ int rdtk_button_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint1 uint16_t textHeight; uint16_t fillWidth; uint16_t fillHeight; - rdtkFont* font; - rdtkEngine* engine; - rdtkNinePatch* ninePatch; - engine = surface->engine; - font = engine->font; - button = engine->button; - ninePatch = button->ninePatch; + WINPR_ASSERT(surface); + WINPR_ASSERT(button); + WINPR_ASSERT(text); + + rdtkEngine* engine = surface->engine; + rdtkFont* font = engine->font; + rdtkNinePatch* ninePatch = button->ninePatch; rdtk_font_text_draw_size(font, &textWidth, &textHeight, text); @@ -70,9 +72,10 @@ int rdtk_button_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint1 rdtkButton* rdtk_button_new(rdtkEngine* engine, rdtkNinePatch* ninePatch) { - rdtkButton* button; + WINPR_ASSERT(engine); + WINPR_ASSERT(ninePatch); - button = (rdtkButton*)calloc(1, sizeof(rdtkButton)); + rdtkButton* button = (rdtkButton*)calloc(1, sizeof(rdtkButton)); if (!button) return NULL; @@ -90,6 +93,8 @@ void rdtk_button_free(rdtkButton* button) int rdtk_button_engine_init(rdtkEngine* engine) { + WINPR_ASSERT(engine); + if (!engine->button) { engine->button = rdtk_button_new(engine, engine->button9patch); @@ -102,6 +107,8 @@ int rdtk_button_engine_init(rdtkEngine* engine) int rdtk_button_engine_uninit(rdtkEngine* engine) { + WINPR_ASSERT(engine); + if (engine->button) { rdtk_button_free(engine->button); diff --git a/rdtk/librdtk/rdtk_engine.c b/rdtk/librdtk/rdtk_engine.c index 4c909aaea..726fa062a 100644 --- a/rdtk/librdtk/rdtk_engine.c +++ b/rdtk/librdtk/rdtk_engine.c @@ -16,6 +16,8 @@ * limitations under the License. */ +#include + #include #include "rdtk_font.h" @@ -27,9 +29,7 @@ rdtkEngine* rdtk_engine_new(void) { - rdtkEngine* engine; - - engine = (rdtkEngine*)calloc(1, sizeof(rdtkEngine)); + rdtkEngine* engine = (rdtkEngine*)calloc(1, sizeof(rdtkEngine)); if (!engine) return NULL; diff --git a/rdtk/librdtk/rdtk_label.c b/rdtk/librdtk/rdtk_label.c index 851beaefd..b49a29918 100644 --- a/rdtk/librdtk/rdtk_label.c +++ b/rdtk/librdtk/rdtk_label.c @@ -16,6 +16,8 @@ * limitations under the License. */ +#include + #include #include "rdtk_font.h" @@ -30,11 +32,11 @@ int rdtk_label_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16 uint16_t offsetY; uint16_t textWidth; uint16_t textHeight; - rdtkFont* font; - rdtkEngine* engine; - engine = surface->engine; - font = engine->font; + WINPR_ASSERT(surface); + + rdtkEngine* engine = surface->engine; + rdtkFont* font = engine->font; rdtk_font_text_draw_size(font, &textWidth, &textHeight, text); @@ -57,9 +59,8 @@ int rdtk_label_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16 rdtkLabel* rdtk_label_new(rdtkEngine* engine) { - rdtkLabel* label; - - label = (rdtkLabel*)calloc(1, sizeof(rdtkLabel)); + WINPR_ASSERT(engine); + rdtkLabel* label = (rdtkLabel*)calloc(1, sizeof(rdtkLabel)); if (!label) return NULL; @@ -76,6 +77,7 @@ void rdtk_label_free(rdtkLabel* label) int rdtk_label_engine_init(rdtkEngine* engine) { + WINPR_ASSERT(engine); if (!engine->label) { engine->label = rdtk_label_new(engine); @@ -86,6 +88,7 @@ int rdtk_label_engine_init(rdtkEngine* engine) int rdtk_label_engine_uninit(rdtkEngine* engine) { + WINPR_ASSERT(engine); if (engine->label) { rdtk_label_free(engine->label); diff --git a/rdtk/librdtk/rdtk_nine_patch.c b/rdtk/librdtk/rdtk_nine_patch.c index f1a91f771..a78de35d7 100644 --- a/rdtk/librdtk/rdtk_nine_patch.c +++ b/rdtk/librdtk/rdtk_nine_patch.c @@ -17,6 +17,7 @@ */ #include +#include #include @@ -34,20 +35,20 @@ static int rdtk_image_copy_alpha_blend(uint8_t* pDstData, int nDstStep, int nXDs int nWidth, int nHeight, uint8_t* pSrcData, int nSrcStep, int nXSrc, int nYSrc) { - int x, y; - uint8_t A, R, G, B; + WINPR_ASSERT(pDstData); + WINPR_ASSERT(pSrcData); - for (y = 0; y < nHeight; y++) + for (int y = 0; y < nHeight; y++) { const uint8_t* pSrcPixel = &pSrcData[((nYSrc + y) * nSrcStep) + (nXSrc * 4)]; uint8_t* pDstPixel = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)]; - for (x = 0; x < nWidth; x++) + for (int x = 0; x < nWidth; x++) { - B = pSrcPixel[0]; - G = pSrcPixel[1]; - R = pSrcPixel[2]; - A = pSrcPixel[3]; + uint8_t B = pSrcPixel[0]; + uint8_t G = pSrcPixel[1]; + uint8_t R = pSrcPixel[2]; + uint8_t A = pSrcPixel[3]; pSrcPixel += 4; if (A == 255) @@ -88,6 +89,9 @@ int rdtk_nine_patch_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth, uint8_t* pDstData; int scaleWidth; + WINPR_ASSERT(surface); + WINPR_ASSERT(ninePatch); + if (nWidth < ninePatch->width) nWidth = ninePatch->width; @@ -217,6 +221,10 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image) int scanline; uint32_t* pixel; int width, height; + + WINPR_ASSERT(ninePatch); + WINPR_ASSERT(image); + ninePatch->image = image; width = image->width; height = image->height; @@ -351,8 +359,8 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image) rdtkNinePatch* rdtk_nine_patch_new(rdtkEngine* engine) { - rdtkNinePatch* ninePatch; - ninePatch = (rdtkNinePatch*)calloc(1, sizeof(rdtkNinePatch)); + WINPR_ASSERT(engine); + rdtkNinePatch* ninePatch = (rdtkNinePatch*)calloc(1, sizeof(rdtkNinePatch)); if (!ninePatch) return NULL; @@ -376,6 +384,8 @@ int rdtk_nine_patch_engine_init(rdtkEngine* engine) wImage* image = NULL; rdtkNinePatch* ninePatch; + WINPR_ASSERT(engine); + if (!engine->button9patch) { SSIZE_T size; @@ -438,6 +448,7 @@ int rdtk_nine_patch_engine_init(rdtkEngine* engine) int rdtk_nine_patch_engine_uninit(rdtkEngine* engine) { + WINPR_ASSERT(engine); if (engine->button9patch) { rdtk_nine_patch_free(engine->button9patch); diff --git a/rdtk/librdtk/rdtk_surface.c b/rdtk/librdtk/rdtk_surface.c index 7ecebf860..d8df46945 100644 --- a/rdtk/librdtk/rdtk_surface.c +++ b/rdtk/librdtk/rdtk_surface.c @@ -16,6 +16,7 @@ * limitations under the License. */ +#include #include #include "rdtk_surface.h" @@ -25,6 +26,8 @@ int rdtk_surface_fill(rdtkSurface* surface, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t color) { + WINPR_ASSERT(surface); + for (uint32_t i = y; i < y * 1ul + height; i++) { uint8_t* line = &surface->data[i * surface->scanline]; @@ -41,6 +44,8 @@ int rdtk_surface_fill(rdtkSurface* surface, uint16_t x, uint16_t y, uint16_t wid rdtkSurface* rdtk_surface_new(rdtkEngine* engine, uint8_t* data, uint16_t width, uint16_t height, uint32_t scanline) { + WINPR_ASSERT(engine); + rdtkSurface* surface = (rdtkSurface*)calloc(1, sizeof(rdtkSurface)); if (!surface) diff --git a/rdtk/librdtk/rdtk_text_field.c b/rdtk/librdtk/rdtk_text_field.c index 1cf5a4c12..a5823d377 100644 --- a/rdtk/librdtk/rdtk_text_field.c +++ b/rdtk/librdtk/rdtk_text_field.c @@ -16,6 +16,8 @@ * limitations under the License. */ +#include + #include #include "rdtk_font.h" @@ -35,6 +37,10 @@ int rdtk_text_field_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, u rdtkEngine* engine; rdtkNinePatch* ninePatch; + WINPR_ASSERT(surface); + WINPR_ASSERT(textField); + WINPR_ASSERT(text); + engine = surface->engine; font = engine->font; textField = surface->engine->textField; @@ -70,9 +76,10 @@ int rdtk_text_field_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, u rdtkTextField* rdtk_text_field_new(rdtkEngine* engine, rdtkNinePatch* ninePatch) { - rdtkTextField* textField; + WINPR_ASSERT(engine); + WINPR_ASSERT(ninePatch); - textField = (rdtkTextField*)calloc(1, sizeof(rdtkTextField)); + rdtkTextField* textField = (rdtkTextField*)calloc(1, sizeof(rdtkTextField)); if (!textField) return NULL; @@ -90,6 +97,8 @@ void rdtk_text_field_free(rdtkTextField* textField) int rdtk_text_field_engine_init(rdtkEngine* engine) { + WINPR_ASSERT(engine); + if (!engine->textField) { engine->textField = rdtk_text_field_new(engine, engine->textField9patch); @@ -102,6 +111,7 @@ int rdtk_text_field_engine_init(rdtkEngine* engine) int rdtk_text_field_engine_uninit(rdtkEngine* engine) { + WINPR_ASSERT(engine); if (engine->textField) { rdtk_text_field_free(engine->textField);