On 10/25/21 12:31 PM, minf...@apache.org wrote:
> Author: minfrin
> Date: Mon Oct 25 10:31:32 2021
> New Revision: 1894551
>
> URL: http://svn.apache.org/viewvc?rev=1894551&view=rev
> Log:
> apr_brigade_split_boundary: Provide a memmem implementation on platforms that
> do not have one.
>
> Modified:
> apr/apr/trunk/buckets/apr_brigade.c
> apr/apr/trunk/configure.in
> apr/apr/trunk/include/apr.h.in
> apr/apr/trunk/include/apr.hnw
> apr/apr/trunk/include/apr.hw
> apr/apr/trunk/include/apr.hwc
>
> Modified: apr/apr/trunk/buckets/apr_brigade.c
> URL:
> http://svn.apache.org/viewvc/apr/apr/trunk/buckets/apr_brigade.c?rev=1894551&r1=1894550&r2=1894551&view=diff
> ==============================================================================
> --- apr/apr/trunk/buckets/apr_brigade.c (original)
> +++ apr/apr/trunk/buckets/apr_brigade.c Mon Oct 25 10:31:32 2021
> @@ -387,6 +387,36 @@ APR_DECLARE(apr_status_t) apr_brigade_sp
> return APR_SUCCESS;
> }
>
> +#if !APR_HAVE_MEMMEM
> +static const void *
> +memmem(const void *hay, size_t hay_len, const void *needle, size_t
> needle_len)
> +{
> +
> + if (hay_len < needle_len || !needle_len || !hay_len) {
> + return NULL;
> + }
> + else {
> +
> + apr_size_t len = hay_len - needle_len + 1;
> + const void *end = hay + hay_len;
> + const void *begin = hay;
begin is unused.
> +
> + while ((hay = memchr(hay, *(char *)needle, len))) {
Does memchr have a defined behaviour for len == 0? This can happen if
*(char *)needle is found at hay[len -1 ] but the memcmp below is not zero.
In this case len becomes 1 below and 0 after the --len.
> + len = end - hay - needle_len + 1;
> +
> + if (memcmp(hay, needle, needle_len) == 0 ) {
> + break;
> + }
> +
> + --len;
> + ++hay;
> + }
> +
> + return hay;
> + }
> +}
> +#endif
> +
> APR_DECLARE(apr_status_t) apr_brigade_split_boundary(apr_bucket_brigade
> *bbOut,
> apr_bucket_brigade
> *bbIn,
> apr_read_type_e block,
>
Regards
RĂ¼diger