]> git.pond.sub.org Git - empserver/commitdiff
(mineq): Rewrite. mineq("dumpcrap", "dump ") now yields ME_MISMATCH
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 13 Jan 2004 17:23:02 +0000 (17:23 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 13 Jan 2004 17:23:02 +0000 (17:23 +0000)
instead of ME_PARTIAL.  Closes #804611.

src/lib/common/stmtch.c

index 2233a98ab1c813cb2cf0d5b5f930ae16fdf930be..bcb4fefe4c96945f9e9ba034eff87a5c913318d8 100644 (file)
@@ -67,16 +67,22 @@ stmtch(register s_char *obj, s_char *base, int off, int size)
 }
 
 /*
- * do partial match comparison.
+ * Compare A with B, up to the first space in B.
+ * Return ME_EXACT if they are the same.
+ * Return ME_PARTIAL if A is a prefix of B.
+ * Else return ME_MISMATCH.
+ * Note: May read B beyond the first space, but not beyond a
+ * terminating 0.
  */
 int
 mineq(register s_char *a, register s_char *b)
 {
-    do {
-       if (*a++ != *b++)
-           return ME_MISMATCH;
-    } while (*b != ' ' && *a != 0);
-    if (*a == 0 && (*b == ' ' || *b == 0))
-       return ME_EXACT;
+    int i;
+
+    /* find common prefix: */
+    for (i = 0; a[i] != 0 && a[i] == b[i]; ++i) ;
+
+    if (a[i] != 0) return ME_MISMATCH;
+    if (b[i] == 0 || b[i] == ' ') return ME_EXACT;
     return ME_PARTIAL;
 }