From b107e4f417cb1a912ada6e0b6af0c01a6aac04bc Mon Sep 17 00:00:00 2001 From: Petro Karashchenko Date: Wed, 21 Dec 2022 00:52:30 +0200 Subject: [PATCH] nuttx: unify MIN, MAX and ABS macro definition across the code Signed-off-by: Petro Karashchenko --- arch/arm/src/imxrt/imxrt_mpuinit.c | 8 ++++---- arch/arm/src/kinetis/kinetis_mpuinit.c | 8 ++++---- arch/arm/src/kinetis/kinetis_usbdev.c | 4 ++-- arch/arm/src/lpc17xx_40xx/lpc17_40_mpuinit.c | 8 ++++---- arch/arm/src/lpc43xx/lpc43_mpuinit.c | 8 ++++---- arch/arm/src/lpc54xx/lpc54_mpuinit.c | 8 ++++---- arch/arm/src/max326xx/common/max326_mpuinit.c | 8 ++++---- arch/arm/src/rtl8720c/amebaz_coex.c | 7 ++++--- arch/arm/src/sam34/sam_mpuinit.c | 8 ++++---- arch/arm/src/sam34/sam_udp.c | 4 ++-- arch/arm/src/sama5/sam_can.c | 4 ++-- arch/arm/src/sama5/sam_hsmci.c | 9 +++++++-- arch/arm/src/sama5/sam_udphs.c | 4 ++-- arch/arm/src/samd2l2/sam_usb.c | 4 ++-- arch/arm/src/samd5e5/sam_mpuinit.c | 8 ++++---- arch/arm/src/samd5e5/sam_usb.c | 4 ++-- arch/arm/src/samv7/sam_hsmci.c | 9 +++++++-- arch/arm/src/samv7/sam_mcan.c | 12 ++++++------ arch/arm/src/samv7/sam_mpuinit.c | 8 ++++---- arch/arm/src/samv7/sam_usbdevhs.c | 4 ++-- arch/arm/src/stm32/stm32_mpuinit.c | 8 ++++---- arch/arm/src/stm32/stm32_usbdev.c | 4 ++-- arch/arm/src/stm32/stm32_usbfs.c | 4 ++-- arch/arm/src/stm32f0l0g0/stm32_usbdev.c | 4 ++-- arch/arm/src/stm32f7/stm32_mpuinit.c | 8 ++++---- arch/arm/src/stm32h7/stm32_mpuinit.c | 8 ++++---- arch/arm/src/stm32l4/stm32l4_mpuinit.c | 8 ++++---- arch/arm/src/stm32l4/stm32l4_usbdev.c | 4 ++-- arch/arm/src/stm32l5/stm32l5_mpuinit.c | 8 ++++---- arch/arm/src/stm32u5/stm32_mpuinit.c | 8 ++++---- arch/arm/src/stm32wl5/stm32wl5_mpuinit.c | 8 ++++---- arch/arm/src/tiva/common/tiva_mpuinit.c | 9 ++++----- arch/arm/src/xmc4/xmc4_mpuinit.c | 8 ++++---- arch/mips/src/pic32mx/pic32mx_ethernet.c | 5 ++--- arch/mips/src/pic32mx/pic32mx_usbdev.c | 4 ++-- arch/risc-v/src/esp32c3/esp32c3_pm.c | 4 ++-- arch/xtensa/src/esp32/esp32_dma.c | 2 +- arch/xtensa/src/esp32/esp32_emac.c | 2 +- arch/xtensa/src/esp32/esp32_pm.c | 4 ++-- binfmt/elf.c | 2 +- binfmt/nxflat.c | 2 +- boards/arm/sam34/sam4l-xplained/src/sam_slcd.c | 4 ++-- boards/arm/stm32/stm3210e-eval/src/stm32_pmbuttons.c | 5 +++-- boards/arm/stm32/stm32ldiscovery/src/stm32_lcd.c | 4 ++-- .../mips/pic32mx/sure-pic32mx/src/pic32mx_lcd1602.c | 4 ++-- drivers/lcd/st7735.c | 4 +++- drivers/usbdev/cdcacm.h | 4 ++-- drivers/usbdev/cdcecm.h | 2 +- graphics/nxbe/nxbe_setsize.c | 4 ++-- libs/libc/fixedmath/lib_b16atan2.c | 10 +++++----- libs/libc/stdio/lib_libdtoa.c | 4 ++-- libs/libdsp/lib_misc_b16.c | 2 +- sched/module/mod_insmod.c | 2 +- tools/rp2040/make_flash_fs.c | 4 +++- 54 files changed, 159 insertions(+), 145 deletions(-) diff --git a/arch/arm/src/imxrt/imxrt_mpuinit.c b/arch/arm/src/imxrt/imxrt_mpuinit.c index 394f9b658f..a45e6c3fad 100644 --- a/arch/arm/src/imxrt/imxrt_mpuinit.c +++ b/arch/arm/src/imxrt/imxrt_mpuinit.c @@ -41,12 +41,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef CONFIG_ARMV7M_DCACHE diff --git a/arch/arm/src/kinetis/kinetis_mpuinit.c b/arch/arm/src/kinetis/kinetis_mpuinit.c index b619750cc4..d9aaec6e71 100644 --- a/arch/arm/src/kinetis/kinetis_mpuinit.c +++ b/arch/arm/src/kinetis/kinetis_mpuinit.c @@ -40,12 +40,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/kinetis/kinetis_usbdev.c b/arch/arm/src/kinetis/kinetis_usbdev.c index 5a3d3d006e..f62f57c09e 100644 --- a/arch/arm/src/kinetis/kinetis_usbdev.c +++ b/arch/arm/src/kinetis/kinetis_usbdev.c @@ -345,11 +345,11 @@ const struct trace_msg_t g_usb_trace_strings_deverror[] = /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Byte ordering in host-based values */ diff --git a/arch/arm/src/lpc17xx_40xx/lpc17_40_mpuinit.c b/arch/arm/src/lpc17xx_40xx/lpc17_40_mpuinit.c index 1b6c64820e..ce2e4cf386 100644 --- a/arch/arm/src/lpc17xx_40xx/lpc17_40_mpuinit.c +++ b/arch/arm/src/lpc17xx_40xx/lpc17_40_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/lpc43xx/lpc43_mpuinit.c b/arch/arm/src/lpc43xx/lpc43_mpuinit.c index 5bf2a4966f..9ef5f66162 100644 --- a/arch/arm/src/lpc43xx/lpc43_mpuinit.c +++ b/arch/arm/src/lpc43xx/lpc43_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/lpc54xx/lpc54_mpuinit.c b/arch/arm/src/lpc54xx/lpc54_mpuinit.c index cf5fd7e31b..63afefc76c 100644 --- a/arch/arm/src/lpc54xx/lpc54_mpuinit.c +++ b/arch/arm/src/lpc54xx/lpc54_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/max326xx/common/max326_mpuinit.c b/arch/arm/src/max326xx/common/max326_mpuinit.c index f6807c7f79..c95c650b7a 100644 --- a/arch/arm/src/max326xx/common/max326_mpuinit.c +++ b/arch/arm/src/max326xx/common/max326_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/rtl8720c/amebaz_coex.c b/arch/arm/src/rtl8720c/amebaz_coex.c index a61c3391d3..502dcd90e0 100644 --- a/arch/arm/src/rtl8720c/amebaz_coex.c +++ b/arch/arm/src/rtl8720c/amebaz_coex.c @@ -30,6 +30,10 @@ * Pre-processor Definitions ****************************************************************************/ +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + #define HCI_VENDOR_MAILBOX_CMD 0xfc8f /* static net_buf_simple *Xiaomi_buf; */ @@ -110,9 +114,6 @@ void bt_coex_handle_specific_evt(uint8_t *p, uint8_t len) rltk_coex_mailbox_to_wifi(p, len); } -#ifndef MIN -# define MIN(a,b) (a < b ? a : b) -#endif static const char *bt_hex_real(const void *buf, size_t len) { static const char hex[] = "0123456789abcdef"; diff --git a/arch/arm/src/sam34/sam_mpuinit.c b/arch/arm/src/sam34/sam_mpuinit.c index dee65fe58d..e3c57ad0e5 100644 --- a/arch/arm/src/sam34/sam_mpuinit.c +++ b/arch/arm/src/sam34/sam_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/sam34/sam_udp.c b/arch/arm/src/sam34/sam_udp.c index c7ac175fa1..4aa09e3bdc 100644 --- a/arch/arm/src/sam34/sam_udp.c +++ b/arch/arm/src/sam34/sam_udp.c @@ -178,11 +178,11 @@ /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Byte ordering in host-based values */ diff --git a/arch/arm/src/sama5/sam_can.c b/arch/arm/src/sama5/sam_can.c index 55e0b29584..5ae6c9dbb0 100644 --- a/arch/arm/src/sama5/sam_can.c +++ b/arch/arm/src/sama5/sam_can.c @@ -80,11 +80,11 @@ /* Common definitions *******************************************************/ #ifndef MIN -# define MIN(a,b) ((a < b) ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) ((a > b) ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Mailboxes ****************************************************************/ diff --git a/arch/arm/src/sama5/sam_hsmci.c b/arch/arm/src/sama5/sam_hsmci.c index d76405de0e..a71366b767 100644 --- a/arch/arm/src/sama5/sam_hsmci.c +++ b/arch/arm/src/sama5/sam_hsmci.c @@ -340,8 +340,13 @@ /* Some semi-standard definitions */ -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif /**************************************************************************** * Private Types diff --git a/arch/arm/src/sama5/sam_udphs.c b/arch/arm/src/sama5/sam_udphs.c index 41cf3823f6..6c765b46a5 100644 --- a/arch/arm/src/sama5/sam_udphs.c +++ b/arch/arm/src/sama5/sam_udphs.c @@ -210,11 +210,11 @@ /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Byte ordering in host-based values */ diff --git a/arch/arm/src/samd2l2/sam_usb.c b/arch/arm/src/samd2l2/sam_usb.c index 86aa252448..acdaef61c4 100644 --- a/arch/arm/src/samd2l2/sam_usb.c +++ b/arch/arm/src/samd2l2/sam_usb.c @@ -214,11 +214,11 @@ /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Byte ordering in host-based values */ diff --git a/arch/arm/src/samd5e5/sam_mpuinit.c b/arch/arm/src/samd5e5/sam_mpuinit.c index a0b52528fc..f48d3591d7 100644 --- a/arch/arm/src/samd5e5/sam_mpuinit.c +++ b/arch/arm/src/samd5e5/sam_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/samd5e5/sam_usb.c b/arch/arm/src/samd5e5/sam_usb.c index f1c401891e..87e6d149e4 100644 --- a/arch/arm/src/samd5e5/sam_usb.c +++ b/arch/arm/src/samd5e5/sam_usb.c @@ -236,11 +236,11 @@ /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Byte ordering in host-based values */ diff --git a/arch/arm/src/samv7/sam_hsmci.c b/arch/arm/src/samv7/sam_hsmci.c index 6df4d27b9b..84926ee388 100644 --- a/arch/arm/src/samv7/sam_hsmci.c +++ b/arch/arm/src/samv7/sam_hsmci.c @@ -273,8 +273,13 @@ /* Some semi-standard definitions */ -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif /**************************************************************************** * Private Types diff --git a/arch/arm/src/samv7/sam_mcan.c b/arch/arm/src/samv7/sam_mcan.c index 567945447c..8c06a22629 100644 --- a/arch/arm/src/samv7/sam_mcan.c +++ b/arch/arm/src/samv7/sam_mcan.c @@ -62,11 +62,11 @@ /* Common definitions *******************************************************/ #ifndef MIN -# define MIN(a,b) ((a < b) ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) ((a > b) ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Clock source *************************************************************/ @@ -131,7 +131,7 @@ # define MCAN0_TSEG1 (CONFIG_SAMV7_MCAN0_PROPSEG + CONFIG_SAMV7_MCAN0_PHASESEG1) # define MCAN0_TSEG2 CONFIG_SAMV7_MCAN0_PHASESEG2 -# define MCAN0_BRP ((uint32_t)(((float) SAMV7_MCANCLK_FREQUENCY / \ +# define MCAN0_BRP ((uint32_t)(((float)SAMV7_MCANCLK_FREQUENCY / \ ((float)(MCAN0_TSEG1 + MCAN0_TSEG2 + 3) * \ (float)CONFIG_SAMV7_MCAN0_BITRATE)) - 1)) # define MCAN0_SJW (CONFIG_SAMV7_MCAN0_FSJW - 1) @@ -148,7 +148,7 @@ # define MCAN0_DTSEG1 (CONFIG_SAMV7_MCAN0_FPROPSEG + CONFIG_SAMV7_MCAN0_FPHASESEG1) # define MCAN0_DTSEG2 (CONFIG_SAMV7_MCAN0_FPHASESEG2) -# define MCAN0_DBRP ((uint32_t)(((float) SAMV7_MCANCLK_FREQUENCY / \ +# define MCAN0_DBRP ((uint32_t)(((float)SAMV7_MCANCLK_FREQUENCY / \ ((float)(MCAN0_DTSEG1 + MCAN0_DTSEG2 + 3) * \ (float)CONFIG_SAMV7_MCAN0_FBITRATE)) - 1)) # define MCAN0_DSJW (CONFIG_SAMV7_MCAN0_FFSJW - 1) @@ -416,7 +416,7 @@ # define MCAN1_TSEG1 (CONFIG_SAMV7_MCAN1_PROPSEG + CONFIG_SAMV7_MCAN1_PHASESEG1) # define MCAN1_TSEG2 CONFIG_SAMV7_MCAN1_PHASESEG2 -# define MCAN1_BRP ((uint32_t)(((float) SAMV7_MCANCLK_FREQUENCY / \ +# define MCAN1_BRP ((uint32_t)(((float)SAMV7_MCANCLK_FREQUENCY / \ ((float)(MCAN1_TSEG1 + MCAN1_TSEG2 + 3) * \ (float)CONFIG_SAMV7_MCAN1_BITRATE)) - 1)) # define MCAN1_SJW (CONFIG_SAMV7_MCAN1_FSJW - 1) @@ -433,7 +433,7 @@ # define MCAN1_DTSEG1 (CONFIG_SAMV7_MCAN1_FPROPSEG + CONFIG_SAMV7_MCAN1_FPHASESEG1) # define MCAN1_DTSEG2 (CONFIG_SAMV7_MCAN1_FPHASESEG2) -# define MCAN1_DBRP ((uint32_t)(((float) SAMV7_MCANCLK_FREQUENCY / \ +# define MCAN1_DBRP ((uint32_t)(((float)SAMV7_MCANCLK_FREQUENCY / \ ((float)(MCAN1_DTSEG1 + MCAN1_DTSEG2 + 3) * \ (float)CONFIG_SAMV7_MCAN1_FBITRATE)) - 1)) # define MCAN1_DSJW (CONFIG_SAMV7_MCAN1_FFSJW - 1) diff --git a/arch/arm/src/samv7/sam_mpuinit.c b/arch/arm/src/samv7/sam_mpuinit.c index d2bd68de0d..bac3665012 100644 --- a/arch/arm/src/samv7/sam_mpuinit.c +++ b/arch/arm/src/samv7/sam_mpuinit.c @@ -41,12 +41,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/samv7/sam_usbdevhs.c b/arch/arm/src/samv7/sam_usbdevhs.c index afbf4d8cd5..47887d1f4f 100644 --- a/arch/arm/src/samv7/sam_usbdevhs.c +++ b/arch/arm/src/samv7/sam_usbdevhs.c @@ -274,11 +274,11 @@ /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Byte ordering in host-based values */ diff --git a/arch/arm/src/stm32/stm32_mpuinit.c b/arch/arm/src/stm32/stm32_mpuinit.c index 0c93e332d4..65a168c034 100644 --- a/arch/arm/src/stm32/stm32_mpuinit.c +++ b/arch/arm/src/stm32/stm32_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/stm32/stm32_usbdev.c b/arch/arm/src/stm32/stm32_usbdev.c index dc70cad438..5285f1e8ea 100644 --- a/arch/arm/src/stm32/stm32_usbdev.c +++ b/arch/arm/src/stm32/stm32_usbdev.c @@ -235,11 +235,11 @@ /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Byte ordering in host-based values */ diff --git a/arch/arm/src/stm32/stm32_usbfs.c b/arch/arm/src/stm32/stm32_usbfs.c index 3205b2638e..25fb21ccc4 100644 --- a/arch/arm/src/stm32/stm32_usbfs.c +++ b/arch/arm/src/stm32/stm32_usbfs.c @@ -216,11 +216,11 @@ /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Byte ordering in host-based values */ diff --git a/arch/arm/src/stm32f0l0g0/stm32_usbdev.c b/arch/arm/src/stm32f0l0g0/stm32_usbdev.c index a213f884b4..80b1c337fa 100644 --- a/arch/arm/src/stm32f0l0g0/stm32_usbdev.c +++ b/arch/arm/src/stm32f0l0g0/stm32_usbdev.c @@ -220,11 +220,11 @@ /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Byte ordering in host-based values */ diff --git a/arch/arm/src/stm32f7/stm32_mpuinit.c b/arch/arm/src/stm32f7/stm32_mpuinit.c index 3f26945b48..ffac20ff1e 100644 --- a/arch/arm/src/stm32f7/stm32_mpuinit.c +++ b/arch/arm/src/stm32f7/stm32_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/stm32h7/stm32_mpuinit.c b/arch/arm/src/stm32h7/stm32_mpuinit.c index 7194aafd66..962c3563b8 100644 --- a/arch/arm/src/stm32h7/stm32_mpuinit.c +++ b/arch/arm/src/stm32h7/stm32_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/stm32l4/stm32l4_mpuinit.c b/arch/arm/src/stm32l4/stm32l4_mpuinit.c index b7440c9a1c..379f275ebf 100644 --- a/arch/arm/src/stm32l4/stm32l4_mpuinit.c +++ b/arch/arm/src/stm32l4/stm32l4_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/stm32l4/stm32l4_usbdev.c b/arch/arm/src/stm32l4/stm32l4_usbdev.c index d6bba1652e..177e499da2 100644 --- a/arch/arm/src/stm32l4/stm32l4_usbdev.c +++ b/arch/arm/src/stm32l4/stm32l4_usbdev.c @@ -220,11 +220,11 @@ /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Byte ordering in host-based values */ diff --git a/arch/arm/src/stm32l5/stm32l5_mpuinit.c b/arch/arm/src/stm32l5/stm32l5_mpuinit.c index cca06140e5..44832bc9f7 100644 --- a/arch/arm/src/stm32l5/stm32l5_mpuinit.c +++ b/arch/arm/src/stm32l5/stm32l5_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/stm32u5/stm32_mpuinit.c b/arch/arm/src/stm32u5/stm32_mpuinit.c index 8acfd881ab..9c60d4b53e 100644 --- a/arch/arm/src/stm32u5/stm32_mpuinit.c +++ b/arch/arm/src/stm32u5/stm32_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/stm32wl5/stm32wl5_mpuinit.c b/arch/arm/src/stm32wl5/stm32wl5_mpuinit.c index a6bd84f6a6..166104dbf1 100644 --- a/arch/arm/src/stm32wl5/stm32wl5_mpuinit.c +++ b/arch/arm/src/stm32wl5/stm32wl5_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/arm/src/tiva/common/tiva_mpuinit.c b/arch/arm/src/tiva/common/tiva_mpuinit.c index 14d88d0790..a2a7ad0906 100644 --- a/arch/arm/src/tiva/common/tiva_mpuinit.c +++ b/arch/arm/src/tiva/common/tiva_mpuinit.c @@ -37,14 +37,13 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b -#endif - #ifndef MIN -# define MIN(a,b) a < b ? a : b +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif /**************************************************************************** * Private Data ****************************************************************************/ diff --git a/arch/arm/src/xmc4/xmc4_mpuinit.c b/arch/arm/src/xmc4/xmc4_mpuinit.c index 5a65afbe2a..a564cc995e 100644 --- a/arch/arm/src/xmc4/xmc4_mpuinit.c +++ b/arch/arm/src/xmc4/xmc4_mpuinit.c @@ -37,12 +37,12 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a,b) a > b ? a : b +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) a < b ? a : b +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/arch/mips/src/pic32mx/pic32mx_ethernet.c b/arch/mips/src/pic32mx/pic32mx_ethernet.c index ae33eeca1a..6f2bd5547b 100644 --- a/arch/mips/src/pic32mx/pic32mx_ethernet.c +++ b/arch/mips/src/pic32mx/pic32mx_ethernet.c @@ -271,13 +271,12 @@ /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif - /**************************************************************************** * Private Types ****************************************************************************/ diff --git a/arch/mips/src/pic32mx/pic32mx_usbdev.c b/arch/mips/src/pic32mx/pic32mx_usbdev.c index 1faf13927d..4946649838 100644 --- a/arch/mips/src/pic32mx/pic32mx_usbdev.c +++ b/arch/mips/src/pic32mx/pic32mx_usbdev.c @@ -243,11 +243,11 @@ /* Ever-present MIN and MAX macros */ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Byte ordering in host-based values */ diff --git a/arch/risc-v/src/esp32c3/esp32c3_pm.c b/arch/risc-v/src/esp32c3/esp32c3_pm.c index a88b608ca1..88edee89e7 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_pm.c +++ b/arch/risc-v/src/esp32c3/esp32c3_pm.c @@ -75,7 +75,7 @@ #define RTC_MODULE_SLEEP_PREPARE_CYCLES (6) #ifndef MAX -#define MAX(a,b) a > b ? a : b +# define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif /* Time from VDD_SDIO power up to first flash read in ROM code */ @@ -1193,4 +1193,4 @@ uint32_t IRAM_ATTR esp32c3_pm_lockstatus(void) return pm_wakelock; } -#endif /* CONFIG_PM */ \ No newline at end of file +#endif /* CONFIG_PM */ diff --git a/arch/xtensa/src/esp32/esp32_dma.c b/arch/xtensa/src/esp32/esp32_dma.c index 532ce0bd4b..5c4e320b37 100644 --- a/arch/xtensa/src/esp32/esp32_dma.c +++ b/arch/xtensa/src/esp32/esp32_dma.c @@ -35,7 +35,7 @@ ****************************************************************************/ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef ALIGN_UP diff --git a/arch/xtensa/src/esp32/esp32_emac.c b/arch/xtensa/src/esp32/esp32_emac.c index daa6ac7f6b..5f758e2a8d 100644 --- a/arch/xtensa/src/esp32/esp32_emac.c +++ b/arch/xtensa/src/esp32/esp32_emac.c @@ -170,7 +170,7 @@ #ifdef MIN # undef MIN -# define MIN(a,b) (((a)<(b))?(a):(b)) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif /* Check if current TX description is busy */ diff --git a/arch/xtensa/src/esp32/esp32_pm.c b/arch/xtensa/src/esp32/esp32_pm.c index 0bf60c6de8..4631af7702 100644 --- a/arch/xtensa/src/esp32/esp32_pm.c +++ b/arch/xtensa/src/esp32/esp32_pm.c @@ -66,7 +66,7 @@ #define LIGHT_SLEEP_MIN_TIME_US 200 #ifndef MAX -#define MAX(a,b) a > b ? a : b +# define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif /* Time from VDD_SDIO power up to first flash read in ROM code */ @@ -1170,4 +1170,4 @@ uint32_t IRAM_ATTR esp32_pm_lockstatus(void) return pm_wakelock; } -#endif /* CONFIG_PM */ \ No newline at end of file +#endif /* CONFIG_PM */ diff --git a/binfmt/elf.c b/binfmt/elf.c index ef225ec06e..6fb0371a54 100644 --- a/binfmt/elf.c +++ b/binfmt/elf.c @@ -61,7 +61,7 @@ #endif #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/binfmt/nxflat.c b/binfmt/nxflat.c index 9eac32ea63..46fcff828c 100644 --- a/binfmt/nxflat.c +++ b/binfmt/nxflat.c @@ -58,7 +58,7 @@ #endif #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/boards/arm/sam34/sam4l-xplained/src/sam_slcd.c b/boards/arm/sam34/sam4l-xplained/src/sam_slcd.c index 132dc65e98..3dd6553b9b 100644 --- a/boards/arm/sam34/sam4l-xplained/src/sam_slcd.c +++ b/boards/arm/sam34/sam4l-xplained/src/sam_slcd.c @@ -71,11 +71,11 @@ /* The ever-present MIN/MAX macros ******************************************/ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* LCD **********************************************************************/ diff --git a/boards/arm/stm32/stm3210e-eval/src/stm32_pmbuttons.c b/boards/arm/stm32/stm3210e-eval/src/stm32_pmbuttons.c index 69a3b59c59..078aa259ef 100644 --- a/boards/arm/stm32/stm3210e-eval/src/stm32_pmbuttons.c +++ b/boards/arm/stm32/stm3210e-eval/src/stm32_pmbuttons.c @@ -99,10 +99,11 @@ /* Miscellaneous Definitions ************************************************/ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif + #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif #define MIN_BUTTON MIN(CONFIG_PM_BUTTONS_MIN, CONFIG_PM_IRQBUTTONS_MIN) diff --git a/boards/arm/stm32/stm32ldiscovery/src/stm32_lcd.c b/boards/arm/stm32/stm32ldiscovery/src/stm32_lcd.c index 201eece029..d4859819c2 100644 --- a/boards/arm/stm32/stm32ldiscovery/src/stm32_lcd.c +++ b/boards/arm/stm32/stm32ldiscovery/src/stm32_lcd.c @@ -74,11 +74,11 @@ /* The ever-present MIN/MAX macros ******************************************/ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* LCD **********************************************************************/ diff --git a/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_lcd1602.c b/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_lcd1602.c index 6ae3d987c6..1baf1a8cf0 100644 --- a/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_lcd1602.c +++ b/boards/mips/pic32mx/sure-pic32mx/src/pic32mx_lcd1602.c @@ -100,11 +100,11 @@ /* The ever-present MIN/MAX macros ******************************************/ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* LCD **********************************************************************/ diff --git a/drivers/lcd/st7735.c b/drivers/lcd/st7735.c index d940d976f7..bbb2835182 100644 --- a/drivers/lcd/st7735.c +++ b/drivers/lcd/st7735.c @@ -45,7 +45,9 @@ * Pre-processor Definitions ****************************************************************************/ -#define MAX(a,b) ((a)>(b)?(a):(b)) +#ifndef MAX +# define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif /* Verify that all configuration requirements have been met */ diff --git a/drivers/usbdev/cdcacm.h b/drivers/usbdev/cdcacm.h index 3c423abbac..53d69a84f1 100644 --- a/drivers/usbdev/cdcacm.h +++ b/drivers/usbdev/cdcacm.h @@ -170,11 +170,11 @@ /* MIN/MAX macros */ #ifndef MIN -# define MIN(a,b) ((a)<(b)?(a):(b)) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) ((a)>(b)?(a):(b)) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Trace values *************************************************************/ diff --git a/drivers/usbdev/cdcecm.h b/drivers/usbdev/cdcecm.h index c84fab5f73..404deaebe7 100644 --- a/drivers/usbdev/cdcecm.h +++ b/drivers/usbdev/cdcecm.h @@ -58,7 +58,7 @@ #define CDCECM_REMOTEWAKEUP (0) #ifndef MIN -# define MIN(a,b) ((a)<(b)?(a):(b)) +# define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif #endif /* __DRIVERS_USBDEV_CDCECM_H */ diff --git a/graphics/nxbe/nxbe_setsize.c b/graphics/nxbe/nxbe_setsize.c index 5a53dd93f4..6a05f506df 100644 --- a/graphics/nxbe/nxbe_setsize.c +++ b/graphics/nxbe/nxbe_setsize.c @@ -46,11 +46,11 @@ ****************************************************************************/ #ifndef MIN -# define MIN(a,b) ((a < b) ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) ((a > b) ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/libs/libc/fixedmath/lib_b16atan2.c b/libs/libc/fixedmath/lib_b16atan2.c index 02c485be47..beb135ad4a 100644 --- a/libs/libc/fixedmath/lib_b16atan2.c +++ b/libs/libc/fixedmath/lib_b16atan2.c @@ -37,16 +37,16 @@ #define B16_HALFPI 0x00019220 /* 1.570796327 */ #define B16_PI 0x00032440 /* 3.141592654 */ -#ifndef MAX -# define MAX(a,b) (a > b ? a : b) +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef MIN -# define MIN(a,b) (a < b ? a : b) +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef ABS -# define ABS(a) (a < 0 ? -a : a) +# define ABS(a) ((a) < 0 ? -(a) : (a)) #endif /**************************************************************************** diff --git a/libs/libc/stdio/lib_libdtoa.c b/libs/libc/stdio/lib_libdtoa.c index 47882fd2d5..7f8890df31 100644 --- a/libs/libc/stdio/lib_libdtoa.c +++ b/libs/libc/stdio/lib_libdtoa.c @@ -59,11 +59,11 @@ ****************************************************************************/ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX -# define MAX(a,b) (a > b ? a : b) +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif /* Use the maximim precision with %g format if no precision is specified. diff --git a/libs/libdsp/lib_misc_b16.c b/libs/libdsp/lib_misc_b16.c index c2e8911db0..7319ab6ef3 100644 --- a/libs/libdsp/lib_misc_b16.c +++ b/libs/libdsp/lib_misc_b16.c @@ -32,7 +32,7 @@ #define FAST_ATAN2_SMALLNUM (1) #ifndef ABS -# define ABS(a) (a < 0 ? -a : a) +# define ABS(a) ((a) < 0 ? -(a) : (a)) #endif /**************************************************************************** diff --git a/sched/module/mod_insmod.c b/sched/module/mod_insmod.c index e63f0132a2..e8371e8d5c 100644 --- a/sched/module/mod_insmod.c +++ b/sched/module/mod_insmod.c @@ -43,7 +43,7 @@ ****************************************************************************/ #ifndef MIN -# define MIN(a,b) (a < b ? a : b) +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif /**************************************************************************** diff --git a/tools/rp2040/make_flash_fs.c b/tools/rp2040/make_flash_fs.c index 3607f21397..123aba717f 100644 --- a/tools/rp2040/make_flash_fs.c +++ b/tools/rp2040/make_flash_fs.c @@ -38,7 +38,9 @@ * Pre-processor Definitions ****************************************************************************/ -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif #define MAX_NAME_LEN 16 #define MAX_SECTOR_DATA (1024 - 10)