Files
Patrick Steinhardt 74a1557b6c util: provide git__memmem function
Unfortunately, neither the `memmem` nor the `strnstr` functions are part
of any C standard but are merely extensions of C that are implemented by
e.g. glibc. Thus, there is no standardized way to search for a string in
a block of memory with a limited size, and using `strstr` is to be
considered unsafe in case where the buffer has not been sanitized. In
fact, there are some uses of `strstr` in exactly that unsafe way in our
codebase.

Provide a new function `git__memmem` that implements the `memmem`
semantics. That is in a given haystack of `n` bytes, search for the
occurrence of a byte sequence of `m` bytes and return a pointer to the
first occurrence. The implementation chosen is the "Not So Naive"
algorithm from [1]. It was chosen as the implementation is comparably
simple while still being reasonably efficient in most cases.
Preprocessing happens in constant time and space, searching has a time
complexity of O(n*m) with a slightly sub-linear average case.

[1]: http://www-igm.univ-mlv.fr/~lecroq/string/

(cherry picked from commit 83e8a6b36a)
2018-10-25 12:56:06 +02:00
..
2016-03-31 10:41:33 -04:00
2015-09-13 13:52:23 -04:00
2016-11-18 16:52:28 +00:00
2018-10-25 12:56:06 +02:00
2015-09-27 23:32:20 +02:00
2017-02-17 11:41:06 +01:00
2016-02-22 23:07:30 -05:00
2017-02-17 11:41:06 +01:00
2016-07-05 18:10:24 +03:00
2016-10-27 11:26:52 +02:00