Eric Blake <[EMAIL PROTECTED]> writes:
> Simon Josefsson <simon <at> josefsson.org> writes:
>
>> > return !result || !memmem ("a", 1, 0, 0);]])],
>> >
>> Ah, thanks. This was not part of the old memmem.m4 checks. Still, the
>> glibc documentation (which I regard as the memmem specification) doesn't
>> say what should be returned for empty needles. My conclusion is that
>> empty needles should lead to undefined behaviour.
>
> Fair enough for the memmem-simple module. But since POSIX requires that 0-
> length needles in strstr(ptr,"") return ptr, and I consider that the
> similarity
> between memmem and strstr is essential, (in part so someone could do a naive
> implementation of strstr as:
> return memmem (haystack, strlen (haystack), needle, strlen (needle));
> and in part because if the haystack length is known in advance, memmem can be
> more efficient than strstr). Therefore, the full memmem module should
> enforce
> an empty needle as well-defined behavior. (Or, put another way, I
> want 'echo "index(abc,)"|m4' to work without me having to special case
> whether
> the second argument to index is empty).
I hadn't considered the strstr similarity here. I think that is a
fairly strong argument that empty needles should return pointers too
even for memmem. But until the documentation actually states it, I
think people need to be careful about empty needles anyway.
>> Unfortunately, cross-compilation is in practice the typical scenario
>> where people care about size issues, so I would prefer to rely on
>> AC_CHECK_FUNC instead.
>
> OK then, based on this email, the gl_FUNC_MEMMEM_SIMPLE macro uses
> AC_CHECK_FUNC when cross-compiling, while gl_FUNC_MEMMEM is pessimistic and
> always uses the replacement (unless you did primed the cache with
> gl_cv_func_memmem_works=yes first). Clients of memmem-simple must avoid
> empty
> needles, and should avoid arbitrary needles, and as a result get smaller code
> size on glibc and cygwin.
Right.
> Here's what I'm committing (I reversed your proposed macro dependency - the
> full module should depend on and augment the simple check, not the other way
> around):
Excellent. Thank you very much for discussing and addressing this.
I'll update gnutls and will report back any problems.
Regards,
/Simon