]> diplodocus.org Git - nmh/blobdiff - sbr/smatch.c
Fix invalid pointer arithmetic.
[nmh] / sbr / smatch.c
index 54ff550e4baf7ca0ecb60d29b58cbe4c8157fb8d..802e4da06a541f8b9db37f7c35b02f79bfc7af6e 100644 (file)
@@ -1,19 +1,19 @@
-
-/*
- * smatch.c -- match a switch (option)
+/* smatch.c -- match a switch (option)
  *
- * $Id$
+ * This code is Copyright (c) 2002, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
  */
 
 #include <h/mh.h>
 
 
 int
-smatch(char *string, struct swit *swp)
+smatch(const char *string, const struct swit *swp)
 {
-    char *sp, *tcp;
+    const char *sp, *tcp;
     int firstone, len;
-    struct swit *tp;
+    const struct swit *tp;
 
     firstone = UNKWNSW;
 
@@ -27,19 +27,19 @@ smatch(char *string, struct swit *swp)
            continue;                   /* no match */
        for (sp = string; *sp == *tcp++;) {
            if (*sp++ == '\0')
-               return (tp - swp);      /* exact match */
+               return tp->swret;       /* exact match */
        }
        if (*sp) {
            if (*sp != ' ')
                continue;               /* no match */
            if (*--tcp == '\0')
-               return (tp - swp);      /* exact match */
+               return tp->swret;       /* exact match */
        }
        if (firstone == UNKWNSW)
-           firstone = tp - swp;
+           firstone = tp->swret;
        else
            firstone = AMBIGSW;
     }
 
-    return (firstone);
+    return firstone;
 }