]> git.pond.sub.org Git - empserver/commitdiff
Change stmtch() to recognize only null as sentinel
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 25 Apr 2011 12:21:44 +0000 (14:21 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 25 Jun 2011 14:51:56 +0000 (16:51 +0200)
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

index 819cda1579dbdb36c51815b5045a0715a3485ef5..9b1074e046a9ec020a523afea6cc41b44bb06df8 100644 (file)
  * 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
 }
 
 /*