packaging: Add contrib installation
[platform/upstream/git.git] / kwset.c
diff --git a/kwset.c b/kwset.c
index 51b2ab6..fc439e0 100644 (file)
--- a/kwset.c
+++ b/kwset.c
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
-   02110-1301, USA.  */
+   along with this program; if not, see <http://www.gnu.org/licenses/>. */
 
 /* Written August 1989 by Mike Haertel.
    The author may be reached (Email) at the address mike@ai.mit.edu,
    or (US mail) as Mike Haertel c/o Free Software Foundation. */
 
-/* The algorithm implemented by these routines bears a startling resemblence
+/* The algorithm implemented by these routines bears a startling resemblance
    to one discovered by Beate Commentz-Walter, although it is not identical.
    See "A String Matching Algorithm Fast on the Average," Technical Report,
    IBM-Germany, Scientific Center Heidelberg, Tiergartenstrasse 15, D-6900
 #include "compat/obstack.h"
 
 #define NCHAR (UCHAR_MAX + 1)
-#define obstack_chunk_alloc xmalloc
+/* adapter for `xmalloc()`, which takes `size_t`, not `long` */
+static void *obstack_chunk_alloc(long size)
+{
+       if (size < 0)
+               BUG("Cannot allocate a negative amount: %ld", size);
+       return xmalloc(size);
+}
 #define obstack_chunk_free free
 
 #define U(c) ((unsigned char) (c))
@@ -65,7 +69,7 @@ struct trie
   struct trie *fail;           /* Aho-Corasick failure function. */
   int depth;                   /* Depth of this node from the root. */
   int shift;                   /* Shift function for search failures. */
-  int maxshift;                        /* Max shift of self and descendents. */
+  int maxshift;                        /* Max shift of self and descendants. */
 };
 
 /* Structure returned opaquely to the caller, containing everything. */
@@ -80,13 +84,13 @@ struct kwset
   struct trie *next[NCHAR];    /* Table of children of the root. */
   char *target;                        /* Target string if there's only one. */
   int mind2;                   /* Used in Boyer-Moore search for one string. */
-  char const *trans;           /* Character translation table. */
+  unsigned char const *trans;  /* Character translation table. */
 };
 
 /* Allocate and initialize a keyword set object, returning an opaque
    pointer to it.  Return NULL if memory is not available. */
 kwset_t
-kwsalloc (char const *trans)
+kwsalloc (unsigned char const *trans)
 {
   struct kwset *kwset;
 
@@ -308,7 +312,7 @@ treefails (register struct tree const *tree, struct trie const *fail,
   treefails(tree->rlink, fail, recourse);
 
   /* Find, in the chain of fails going back to the root, the first
-     node that has a descendent on the current label. */
+     node that has a descendant on the current label. */
   while (fail)
     {
       link = fail->links;
@@ -381,7 +385,7 @@ kwsprep (kwset_t kws)
   register struct kwset *kwset;
   register int i;
   register struct trie *curr;
-  register char const *trans;
+  register unsigned char const *trans;
   unsigned char delta[NCHAR];
 
   kwset = (struct kwset *) kws;
@@ -426,16 +430,16 @@ kwsprep (kwset_t kws)
         computing the delta table, failure function, and shift function. */
       for (curr = last = kwset->trie; curr; curr = curr->next)
        {
-         /* Enqueue the immediate descendents in the level order queue. */
+         /* Enqueue the immediate descendants in the level order queue. */
          enqueue(curr->links, &last);
 
          curr->shift = kwset->mind;
          curr->maxshift = kwset->mind;
 
-         /* Update the delta table for the descendents of this node. */
+         /* Update the delta table for the descendants of this node. */
          treedelta(curr->links, curr->depth, delta);
 
-         /* Compute the failure function for the decendents of this node. */
+         /* Compute the failure function for the descendants of this node. */
          treefails(curr->links, curr->fail, kwset->trie);
 
          /* Update the shifts at each node in the current node's chain
@@ -450,7 +454,7 @@ kwsprep (kwset_t kws)
                  fail->shift = curr->depth - fail->depth;
 
              /* If the current node is accepting then the shift at the
-                fail and its descendents should be no larger than the
+                fail and its descendants should be no larger than the
                 difference of their depths. */
              if (curr->accepting && fail->maxshift > curr->depth - fail->depth)
                fail->maxshift = curr->depth - fail->depth;
@@ -477,7 +481,7 @@ kwsprep (kwset_t kws)
        for (i = 0; i < NCHAR; ++i)
          kwset->next[i] = next[U(trans[i])];
       else
-       memcpy(kwset->next, next, NCHAR * sizeof(struct trie *));
+       COPY_ARRAY(kwset->next, next, NCHAR);
     }
 
   /* Fix things up for any translation table. */
@@ -590,7 +594,7 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
   register int d;
   register char const *end, *qlim;
   register struct tree const *tree;
-  register char const *trans;
+  register unsigned char const *trans;
 
   accept = NULL;