From 9c64b6278c160e8db8c3d6b3f66803f3d5906074 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 10 Dec 2020 11:24:09 -0500 Subject: [PATCH] Make sure MIN() and MAX() are always defined. Signed-off-by: Peter Jones --- include/compiler.h | 3 +++ lib/console.c | 2 +- mok.c | 4 ++-- shim.h | 5 ----- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/compiler.h b/include/compiler.h index 48ec009..4e44840 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -149,5 +149,8 @@ #define ALIGN_DOWN(x, a) __ALIGN((x) - ((a) - 1), (a)) #endif +#define MIN(a, b) ({(a) < (b) ? (a) : (b);}) +#define MAX(a, b) ({(a) <= (b) ? (b) : (a);}) + #endif /* !COMPILER_H_ */ // vim:fenc=utf-8:tw=75:et diff --git a/lib/console.c b/lib/console.c index ecd5c0e..00a7baa 100644 --- a/lib/console.c +++ b/lib/console.c @@ -213,7 +213,7 @@ console_print_box_at(CHAR16 *str_arr[], int highlight, if (col < 0) col = 0; - CopyMem(Line + col + 1, s, min(len, size_cols - 2)*2); + CopyMem(Line + col + 1, s, MIN(len, size_cols - 2)*2); } if (line >= 0 && line == highlight) co->SetAttribute(co, EFI_LIGHTGRAY | diff --git a/mok.c b/mok.c index fafcf9f..c8de6a6 100644 --- a/mok.c +++ b/mok.c @@ -253,7 +253,7 @@ mirror_one_esl(CHAR16 *name, EFI_GUID *guid, UINT32 attrs, SIZE_T howmany, varsz = 0, esdsz; UINT8 *var, *data; - howmany = min((maxsz - sizeof(*esl)) / esl->SignatureSize, + howmany = MIN((maxsz - sizeof(*esl)) / esl->SignatureSize, (esl->SignatureListSize - sizeof(*esl)) / esl->SignatureSize); if (howmany < 1) { return EFI_BUFFER_TOO_SMALL; @@ -411,7 +411,7 @@ mirror_mok_db(CHAR16 *name, CHAR8 *name8, EFI_GUID *guid, UINT32 attrs, SIZE_T howmany; UINTN adj = 0; - howmany = min((max_var_sz - sizeof(*esl)) / esl->SignatureSize, + howmany = MIN((max_var_sz - sizeof(*esl)) / esl->SignatureSize, (esl->SignatureListSize - sizeof(*esl)) / esl->SignatureSize); if (!only_first && i == 0 && howmany >= 1) { adj = howmany * esl->SignatureSize; diff --git a/shim.h b/shim.h index fe750e4..44c0155 100644 --- a/shim.h +++ b/shim.h @@ -35,8 +35,6 @@ #define nonnull(...) __attribute__((__nonnull__(__VA_ARGS__))) -#define min(a, b) ({(a) < (b) ? (a) : (b);}) - #ifdef __x86_64__ #ifndef DEFAULT_LOADER #define DEFAULT_LOADER L"\\grubx64.efi" @@ -233,7 +231,4 @@ verify_buffer (char *data, int datasize, #define LogError(fmt, ...) \ LogError_(__FILE__, __LINE__ - 1, __func__, fmt, ##__VA_ARGS__) -#define MIN(a, b) (((a) <= (b))?(a):(b)) -#define MAX(a, b) (((a) <= (b))?(b):(a)) - #endif /* SHIM_H_ */