commit: e3a6b1d54d7afc1d0cacedef1c0fb2ba1809cf0f
parent c584c45eeb9f972ed41ae488530c32de133afcc9
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 23 Sep 2025 11:05:42 +0200
common: use MIN macro
Diffstat:
2 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/common.c b/common.c
@@ -13,11 +13,9 @@
#include <termios.h> // tcgetattr, tcsetattr
#include <unistd.h> // crypt
-size_t
-smin(size_t a, size_t b)
-{
- return a < b ? a : b;
-}
+#ifndef MIN
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
// Needs to be constant-time so the hash can't be guessed via using a rainbow-table
bool
@@ -27,7 +25,7 @@ hash_match(const char *a, const char *b)
size_t len_a = strlen(a);
/* flawfinder: ignore CWE-126 */
size_t len_b = strlen(b);
- size_t n = smin(len_a, len_b);
+ size_t n = MIN(len_a, len_b);
bool ret = true;
for(size_t i = 0; i < n; i++)
diff --git a/common_test.c b/common_test.c
@@ -5,15 +5,6 @@
#include <atf-c.h> // ATF*, atf*
-ATF_TC(smin_tc);
-ATF_TC_HEAD(smin_tc, tc) { atf_tc_set_md_var(tc, "descr", "smin returns correct values"); }
-ATF_TC_BODY(smin_tc, tc)
-{
- ATF_CHECK(smin(1, 2) == 1);
- ATF_CHECK(smin(1, 1) == 1);
- ATF_CHECK(smin(2, 1) == 1);
-}
-
ATF_TC(hash_match_tc);
ATF_TC_HEAD(hash_match_tc, tc)
{
@@ -58,7 +49,6 @@ ATF_TC_BODY(skeud_crypt_check_tc, tc)
ATF_TP_ADD_TCS(tp)
{
- ATF_TP_ADD_TC(tp, smin_tc);
ATF_TP_ADD_TC(tp, hash_match_tc);
ATF_TP_ADD_TC(tp, skeud_crypt_check_tc);