* Fixed types in mem_mem() and correctly attribute the search algorithm.
authorUrban Wallasch <urban.wallasch@freenet.de>
Wed, 13 Nov 2019 14:54:38 +0000 (15:54 +0100)
committerUrban Wallasch <urban.wallasch@freenet.de>
Wed, 13 Nov 2019 14:54:38 +0000 (15:54 +0100)
riffx.c

diff --git a/riffx.c b/riffx.c
index 7d2ee02b3ebec8aee1338ee8311bb45fbfc8bba2..0ebed7697704916f01dd1de592d13703ace6734c 100644 (file)
--- a/riffx.c
+++ b/riffx.c
@@ -100,14 +100,19 @@ int mkdirp(const char *pathname, mode_t mode) {
 
 /* mem_mem
  * Locate needle of length nlen in haystack of length hlen.
- * Returns pointer to first occurrence of needle in haystack or NULL.
- * Uses the Boyer-Moore search algorithm.
- *   Cf. http://www-igm.univ-mlv.fr/~lecroq/string/node14.html
+ * Returns a pointer to the first occurrence of needle in haystack, or
+ * haystack for a needle of zero length, or NULL if needle was not found
+ * in haystack.
+ *
+ * Uses the Boyer-Moore-Horspool search algorithm, see
+ * https://en.wikipedia.org/wiki/Boyer–Moore–Horspool_algorithm
+ *
+ * For our tiny needles and non-pathologic haystacks this borders on
+ * overkill, but meh.
  */
 static void *mem_mem(const void *haystack, size_t hlen,
                      const void *needle, size_t nlen) {
-    size_t k;
-    int skip[256];
+    size_t k, skip[256];
     const uint8_t *hst = (const uint8_t *)haystack;
     const uint8_t *ndl = (const uint8_t *)needle;