From 1e9c9c827337f4327f913e64d92da19711c754f1 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 25 Apr 2011 14:21:44 +0200 Subject: [PATCH] Change stmtch() to recognize only null as sentinel Before, it also recognized "" (since commit 844b654d, v4.2.14), but no caller depends on that. While there, back out the macro cleverness added in commit 844b654d. --- src/lib/common/stmtch.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/common/stmtch.c b/src/lib/common/stmtch.c index 819cda157..9b1074e04 100644 --- a/src/lib/common/stmtch.c +++ b/src/lib/common/stmtch.c @@ -39,19 +39,22 @@ * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are * several. * Each array element has a pointer to its name stored at offset OFFS. - * Search stops when this name is a null pointer or empty. + * Search stops when this name is a null pointer. * NEEDLE is compared to element names with mineq(NEEDLE, NAME). - * ELT_SIZE gives the size of an array element. + * SIZE gives the size of an array element. */ int -stmtch(char *needle, void *haystack, ptrdiff_t offs, size_t elt_size) +stmtch(char *needle, void *haystack, ptrdiff_t offs, size_t size) { -#define ELT_NAME(i) (*(char **)((char *)haystack + (i)*elt_size + offs)) int i, res; + char *name; res = M_NOTFOUND; - for (i = 0; ELT_NAME(i) && ELT_NAME(i)[0] != 0; i++) { - switch (mineq(needle, ELT_NAME(i))) { + for (i = 0;; i++) { + name = *(char **)((char *)haystack + i * size + offs); + if (!name) + break; + switch (mineq(needle, name)) { case ME_MISMATCH: break; case ME_PARTIAL: @@ -65,7 +68,6 @@ stmtch(char *needle, void *haystack, ptrdiff_t offs, size_t elt_size) } } return res; -#undef ELT_NAME } /* -- 2.43.0