From a1f6e04d2338f4e972f055b2425cf0cbd79a28ca Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 4 Oct 2022 21:29:19 +0200 Subject: [PATCH] imlib: Fix possible signed/unsigned comparisons issues. --- src/omv/imlib/agast.c | 4 ++-- src/omv/imlib/blob.c | 4 ++-- src/omv/imlib/clahe.c | 4 ++-- src/omv/imlib/fast.c | 4 ++-- src/omv/imlib/imlib.c | 2 +- src/omv/imlib/imlib.h | 4 ++-- src/omv/ports/stm32/modules/py_lcd.c | 4 ++-- src/omv/ports/stm32/modules/py_tv.c | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/omv/imlib/agast.c b/src/omv/imlib/agast.c index b6bfafb7b..d00e64afa 100644 --- a/src/omv/imlib/agast.c +++ b/src/omv/imlib/agast.c @@ -18,8 +18,8 @@ #include "fb_alloc.h" #include "gc.h" -#define MAX_ROW (480) -#define MAX_CORNERS (2000) +#define MAX_ROW (480u) +#define MAX_CORNERS (2000u) #define Compare(X, Y) ((X)>=(Y)) typedef struct { diff --git a/src/omv/imlib/blob.c b/src/omv/imlib/blob.c index 0574648cd..e8c9f0d19 100644 --- a/src/omv/imlib/blob.c +++ b/src/omv/imlib/blob.c @@ -56,7 +56,7 @@ static void bin_up(uint16_t *hist, uint16_t size, unsigned int max_size, uint16_ end = i; } - int bin_count = end - start + 1; // >= 1 + uint16_t bin_count = end - start + 1; // >= 1 *new_size = IM_MIN(max_size, bin_count); *new_hist = xalloc0((*new_size) * sizeof(uint16_t)); float div_value = (*new_size) / ((float) bin_count); // Reversed so we can multiply below. @@ -74,7 +74,7 @@ static void merge_bins(int b_dst_start, int b_dst_end, uint16_t **b_dst_hist, ui int start = IM_MIN(b_dst_start, b_src_start); int end = IM_MAX(b_dst_end, b_src_end); - int bin_count = end - start + 1; // >= 1 + uint16_t bin_count = end - start + 1; // >= 1 uint16_t new_size = IM_MIN(max_size, bin_count); uint16_t *new_hist = xalloc0(new_size * sizeof(uint16_t)); float div_value = new_size / ((float) bin_count); // Reversed so we can multiply below. diff --git a/src/omv/imlib/clahe.c b/src/omv/imlib/clahe.c index 9868c606f..bc704c7a7 100644 --- a/src/omv/imlib/clahe.c +++ b/src/omv/imlib/clahe.c @@ -316,8 +316,8 @@ void Interpolate (kz_pixel_t * pImage, int uiXRes, unsigned long * pulMapLU, void imlib_clahe_histeq(image_t *img, float clip_limit, image_t *mask) { - int xTileSize = IM_MAX(uiMAX_REG_X >> (10 - IM_MIN(IM_LOG2_32(img->w), 10)), 2); - int yTileSize = IM_MAX(uiMAX_REG_Y >> (10 - IM_MIN(IM_LOG2_32(img->h), 10)), 2); + int xTileSize = IM_MAX(uiMAX_REG_X >> (10 - IM_MIN(IM_LOG2_32(img->w), 10)), 2u); + int yTileSize = IM_MAX(uiMAX_REG_Y >> (10 - IM_MIN(IM_LOG2_32(img->h), 10)), 2u); int pImageW = img->w + ((img->w % xTileSize) ? (xTileSize - (img->w % xTileSize)) : 0); int pImageH = img->h + ((img->h % yTileSize) ? (yTileSize - (img->h % yTileSize)) : 0); int xOffset = (pImageW - img->w) / 2; diff --git a/src/omv/imlib/fast.c b/src/omv/imlib/fast.c index cbf1a02d6..e02be393b 100644 --- a/src/omv/imlib/fast.c +++ b/src/omv/imlib/fast.c @@ -37,8 +37,8 @@ #ifdef IMLIB_ENABLE_FAST -#define MAX_ROW (480) -#define MAX_CORNERS (2000) +#define MAX_ROW (480U) +#define MAX_CORNERS (2000U) #define Compare(X, Y) ((X)>=(Y)) typedef struct { diff --git a/src/omv/imlib/imlib.c b/src/omv/imlib/imlib.c index f035f1341..ee5f4dfe8 100644 --- a/src/omv/imlib/imlib.c +++ b/src/omv/imlib/imlib.c @@ -628,7 +628,7 @@ void imlib_image_operation(image_t *img, const char *path, image_t *other, int s // case we shrink the window size to how many lines we're buffering. temp.pixels = alloc; // Set the max buffer height to image height. - temp.h = IM_MIN(img->h, (size / (temp.w * temp.bpp))); + temp.h = IM_MIN((uint32_t) img->h, (size / (temp.w * temp.bpp))); // This should never happen unless someone forgot to free. if ((!temp.pixels) || (!temp.h)) { mp_raise_msg(&mp_type_MemoryError, MP_ERROR_TEXT("Not enough memory available!")); diff --git a/src/omv/imlib/imlib.h b/src/omv/imlib/imlib.h index f4718562d..494e22f53 100644 --- a/src/omv/imlib/imlib.h +++ b/src/omv/imlib/imlib.h @@ -499,8 +499,8 @@ struct { \ #endif typedef struct image { - uint32_t w; - uint32_t h; + int32_t w; + int32_t h; PIXFORMAT_STRUCT; union { uint8_t *pixels; diff --git a/src/omv/ports/stm32/modules/py_lcd.c b/src/omv/ports/stm32/modules/py_lcd.c index 87f2fb99c..a3c415b9a 100644 --- a/src/omv/ports/stm32/modules/py_lcd.c +++ b/src/omv/ports/stm32/modules/py_lcd.c @@ -274,8 +274,8 @@ static void spi_lcd_callback(SPI_HandleTypeDef *hspi) } case SPI_TX_CB_MEMORY_WRITE: { uint16_t *addr = spi_tx_cb_state_memory_write_addr; - size_t count = IM_MIN(spi_tx_cb_state_memory_write_count, (65536-8)); - spi_tx_cb_state = (spi_tx_cb_state_memory_write_count > (65536-8)) ? SPI_TX_CB_MEMORY_WRITE : SPI_TX_CB_DISPLAY_ON; + size_t count = IM_MIN(spi_tx_cb_state_memory_write_count, (65536-8u)); + spi_tx_cb_state = (spi_tx_cb_state_memory_write_count > (65536-8u)) ? SPI_TX_CB_MEMORY_WRITE : SPI_TX_CB_DISPLAY_ON; spi_tx_cb_state_memory_write_addr += count; spi_tx_cb_state_memory_write_count -= count; if (spi_tx_cb_state_memory_write_first) { diff --git a/src/omv/ports/stm32/modules/py_tv.c b/src/omv/ports/stm32/modules/py_tv.c index 91ca15535..00680a782 100644 --- a/src/omv/ports/stm32/modules/py_tv.c +++ b/src/omv/ports/stm32/modules/py_tv.c @@ -580,7 +580,7 @@ static void spi_tv_callback(SPI_HandleTypeDef *hspi) } case SPI_TX_CB_MEMORY_WRITE: { uint8_t *addr = spi_tx_cb_state_memory_write_addr; - size_t count = IM_MIN(spi_tx_cb_state_memory_write_count, (65536-16)); + size_t count = IM_MIN(spi_tx_cb_state_memory_write_count, (65536-16u)); spi_tx_cb_state = (spi_tx_cb_state_memory_write_count > (65536-16)) ? SPI_TX_CB_MEMORY_WRITE : SPI_TX_CB_MEMORY_WRITE_CMD;