diff --git a/firmware/u2f.c b/firmware/u2f.c index 0db0f3b4e..33a5f1c1d 100644 --- a/firmware/u2f.c +++ b/firmware/u2f.c @@ -40,8 +40,6 @@ #include "u2f_knownapps.h" #include "u2f.h" -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - // About 1/2 Second according to values used in protect.c #define U2F_TIMEOUT (800000/2) #define U2F_OUT_PKT_BUFFER_LEN 128 diff --git a/oled.c b/oled.c index 6daee8a92..0b73db557 100644 --- a/oled.c +++ b/oled.c @@ -306,9 +306,6 @@ void oledDrawStringRight(int x, int y, const char* text) oledDrawString(x, y, text); } -#define max(X,Y) ((X) > (Y) ? (X) : (Y)) -#define min(X,Y) ((X) < (Y) ? (X) : (Y)) - void oledDrawBitmap(int x, int y, const BITMAP *bmp) { for (int i = 0; i < bmp->width; i++) { @@ -327,10 +324,10 @@ void oledDrawBitmap(int x, int y, const BITMAP *bmp) */ void oledInvert(int x1, int y1, int x2, int y2) { - x1 = max(x1, 0); - y1 = max(y1, 0); - x2 = min(x2, OLED_WIDTH - 1); - y2 = min(y2, OLED_HEIGHT - 1); + x1 = MAX(x1, 0); + y1 = MAX(y1, 0); + x2 = MIN(x2, OLED_WIDTH - 1); + y2 = MIN(y2, OLED_HEIGHT - 1); for (int x = x1; x <= x2; x++) { for (int y = y1; y <= y2; y++) { oledInvertPixel(x,y); @@ -343,10 +340,10 @@ void oledInvert(int x1, int y1, int x2, int y2) */ void oledBox(int x1, int y1, int x2, int y2, bool set) { - x1 = max(x1, 0); - y1 = max(y1, 0); - x2 = min(x2, OLED_WIDTH - 1); - y2 = min(y2, OLED_HEIGHT - 1); + x1 = MAX(x1, 0); + y1 = MAX(y1, 0); + x2 = MIN(x2, OLED_WIDTH - 1); + y2 = MIN(y2, OLED_HEIGHT - 1); for (int x = x1; x <= x2; x++) { for (int y = y1; y <= y2; y++) { set ? oledDrawPixel(x, y) : oledClearPixel(x, y); diff --git a/util.h b/util.h index 1494cb6f4..6e5d4e084 100644 --- a/util.h +++ b/util.h @@ -25,6 +25,10 @@ #include #include +// Statement expressions make these macros side-effect safe +#define MIN(a, b) ({ typeof(a) _a = (a); typeof(b) _b = (b); _a > _b ? _a : _b; }) +#define MAX(a, b) ({ typeof(a) _a = (a); typeof(b) _b = (b); _a > _b ? _a : _b; }) + void delay(uint32_t wait); // converts uint32 to hexa (8 digits)