unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: Thomas Schneider <qsx@chaotikum.eu>, notmuch@notmuchmail.org
Cc: Thomas Schneider <qsx@chaotikum.eu>
Subject: Re: [PATCH] compat/strcasestr: Include correct header file
Date: Sat, 03 Dec 2022 11:38:48 +0200	[thread overview]
Message-ID: <y3735fl.g456te-too@iki.fi> (raw)
In-Reply-To: <20221202191908.848227-1-qsx@chaotikum.eu>

On Fri, Dec 02 2022, Thomas Schneider wrote:

> As per strcasestr(3) of glibc and FreeBSD, the header that defines
> strcasestr() is string.h, not strings.h.  This may cause compilation,
> and thus detection whether an (optimised) version is available, to
> fail even if the function is available, when implicit declaration and
> pointer conversion do not match.
>
> Signed-off-by: Thomas Schneider <qsx@chaotikum.eu>
> ---
> I discovered this when building with Clang:
>
> qsx@naboo ~/src/notmuch (git)-[tags/0.32.2]
> % gcc -o /dev/null compat/have_strcasestr.c; echo $?
> compat/have_strcasestr.c: In function ‘main’:
> compat/have_strcasestr.c:10:13: warning: implicit declaration of function ‘strcasestr’; did you mean ‘strcasecmp’? [-Wimplicit-function-declaration]
>    10 |     found = strcasestr (haystack, needle);
>       |             ^~~~~~~~~~
>       |             strcasecmp
> compat/have_strcasestr.c:10:11: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
>    10 |     found = strcasestr (haystack, needle);
>       |           ^
> 0
> qsx@naboo ~/src/notmuch (git)-[tags/0.32.2]
> % clang -o /dev/null compat/have_strcasestr.c; echo $?
> compat/have_strcasestr.c:10:13: warning: call to undeclared function 'strcasestr'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
>     found = strcasestr (haystack, needle);
>             ^
> compat/have_strcasestr.c:10:11: error: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
>     found = strcasestr (haystack, needle);
>           ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 1 warning and 1 error generated.
> 1
>
> configure then assumes strcasestr is not available when using Clang, so it
> builds the variant from compat/, which later fails when linking because of
> conflicting symbols.
>
> On a side note, debugging was more complicated that I’m used to, e. g.,
> autoconf’s config.log or similar output.
>
> ---
>  compat/have_strcasestr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/compat/have_strcasestr.c b/compat/have_strcasestr.c
> index 3cd1838d..d52a62ec 100644
> --- a/compat/have_strcasestr.c
> +++ b/compat/have_strcasestr.c
> @@ -1,5 +1,5 @@
>  #define _GNU_SOURCE
> -#include <strings.h>
> +#include <string.h>

Would it be better to include both strings.h and string.h, in
case some (rare) cases it worked only when strings.h were included
(or would that make the test fail in some cases then...?)


Tomi

>  
>  int
>  main ()
> -- 
> 2.37.4\r

  reply	other threads:[~2022-12-03  9:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 19:19 [PATCH] compat/strcasestr: Include correct header file Thomas Schneider
2022-12-03  9:38 ` Tomi Ollila [this message]
2022-12-03 14:38   ` Thomas Schneider
2022-12-25 23:49     ` Tomi Ollila

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=y3735fl.g456te-too@iki.fi \
    --to=tomi.ollila@iki.fi \
    --cc=notmuch@notmuchmail.org \
    --cc=qsx@chaotikum.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).