Re: [PATCH v2] Fix const warnings on Arch linux with the latest glibc.

Alejandro Colomar via Mutt-dev <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <aZ7xS2P1tk9OP7xY@devuan>
Hi Kevin,

On 2026-02-25T20:27:34+0800, Kevin J. McCarthy wrote:
> The latest version of glibc changes string search functions, such as
> strchr() and strrchr(), so that the return type is the same type as
> the string passed in.
> 
> This helped us catch a real bug in browser.c (3a8dfafc), and also
> turned up some variable type issues, fixed here.
> 
> Thanks to Rene Kita for the work on the Arch sr.ht build files which
> turned up the bugs, and for an initial patch showing where the warning
> were, which this commit is based upon.
> 
> Also thanks to Alejandro Colomar for quickly explaining what was going
> on and helping debug the issues, and for the parse.c bsearch fix.

Thanks for the credit!

> ---

Reviewed-by: Alejandro Colomar <[email protected]>

(feel free to add it or not)


Cheers,
Alex

>  Rene, please double check the revised fix for parse.c bsearch()
>  eliminates the warning.  Thanks Rene and Alejandro!
>  mh.c      |  6 ++++--
>  muttlib.c |  3 ++-
>  parse.c   |  4 ++--
>  rfc1524.c |  7 ++++---
>  sendlib.c |  3 ++-
>  url.c     | 10 ++++++----
>  6 files changed, 20 insertions(+), 13 deletions(-)
> 
> diff --git a/mh.c b/mh.c
> index 4c4c9695..40115db2 100644
> --- a/mh.c
> +++ b/mh.c
> @@ -684,7 +684,8 @@ static void maildir_free_maildir (struct maildir **md)
>  
>  static void maildir_parse_flags (HEADER * h, const char *path)
>  {
> -  char *p, *q = NULL;
> +  const char *p;
> +  char *q = NULL;
>  
>    h->flagged = 0;
>    h->read = 0;
> @@ -2117,7 +2118,8 @@ err:
>  
>  static void maildir_canon_filename (BUFFER *dest, const char *src)
>  {
> -  char *t, *u;
> +  const char *t;
> +  char *u;
>  
>    if ((t = strrchr (src, '/')))
>      src = t + 1;
> diff --git a/muttlib.c b/muttlib.c
> index 18f3ebf0..4c20e8c5 100644
> --- a/muttlib.c
> +++ b/muttlib.c
> @@ -510,7 +510,8 @@ void _mutt_buffer_expand_path (BUFFER *src, int flags)
>          else
>          {
>            struct passwd *pw;
> -          if ((t = strchr (s + 1, '/')))
> +          /* NB: this is temporarily modifying src but is restoring it below */
> +          if ((t = strchr (src->data + 1, '/')))
>              *t = 0;
>  
>            if ((pw = getpwnam (s + 1)))
> diff --git a/parse.c b/parse.c
> index 141947f4..4729f51a 100644
> --- a/parse.c
> +++ b/parse.c
> @@ -825,7 +825,7 @@ BODY *mutt_parse_multipart (FILE *fp, const char *boundary, LOFF_T end_off, int
>  
>  static const char *uncomment_timezone (char *buf, size_t buflen, const char *tz)
>  {
> -  char *p;
> +  const char *p;
>    size_t len;
>  
>    if (*tz != '(')
> @@ -999,7 +999,7 @@ time_t mutt_parse_date (const char *s, HEADER *h)
>          }
>          else
>          {
> -          struct tz_t *tz;
> +          const struct tz_t *tz;
>  
>            tz = bsearch (ptz, TimeZones, sizeof TimeZones/sizeof (struct tz_t),
>                          sizeof (struct tz_t),
> diff --git a/rfc1524.c b/rfc1524.c
> index 273614b1..758e380a 100644
> --- a/rfc1524.c
> +++ b/rfc1524.c
> @@ -208,6 +208,7 @@ static int rfc1524_mailcap_parse (BODY *a,
>    FILE *fp;
>    char *buf = NULL;
>    size_t buflen;
> +  const char *typeslash;
>    char *ch;
>    char *field;
>    int found = FALSE;
> @@ -230,9 +231,9 @@ static int rfc1524_mailcap_parse (BODY *a,
>     */
>  
>    /* find length of basetype */
> -  if ((ch = strchr (type, '/')) == NULL)
> +  if ((typeslash = strchr (type, '/')) == NULL)
>      return FALSE;
> -  btlen = ch - type;
> +  btlen = typeslash - type;
>  
>    if ((fp = fopen (filename, "r")) != NULL)
>    {
> @@ -499,7 +500,7 @@ void mutt_rfc1524_expand_filename (const char *nametemplate,
>                                     BUFFER *newfile)
>  {
>    int i, j, k, ps;
> -  char *s;
> +  const char *s;
>    short lmatch = 0, rmatch = 0;
>    BUFFER *left = NULL;
>    BUFFER *right = NULL;
> diff --git a/sendlib.c b/sendlib.c
> index f0e34d99..a700d500 100644
> --- a/sendlib.c
> +++ b/sendlib.c
> @@ -2100,7 +2100,8 @@ static int write_one_header (FILE *fp, int pfxw, int max, int wraplen,
>                               const char *pfx, const char *start, const char *end,
>                               int flags)
>  {
> -  char *tagbuf, *valbuf, *t;
> +  char *tagbuf, *valbuf;
> +  const char *t;
>    int is_from = ((end - start) > 5 &&
>                   ascii_strncasecmp (start, "from ", 5) == 0);
>  
> diff --git a/url.c b/url.c
> index c1578f42..dfe8bff7 100644
> --- a/url.c
> +++ b/url.c
> @@ -78,7 +78,8 @@ static int url_pct_decode (char *s)
>  url_scheme_t url_check_scheme (const char *s)
>  {
>    char sbuf[STRING];
> -  char *t;
> +  const char *t;
> +  char *sbufp;
>    int i;
>  
>    if (!s || !(t = strchr (s, ':')))
> @@ -87,8 +88,8 @@ url_scheme_t url_check_scheme (const char *s)
>      return U_UNKNOWN;
>  
>    strfcpy (sbuf, s, t - s + 1);
> -  for (t = sbuf; *t; t++)
> -    *t = ascii_tolower (*t);
> +  for (sbufp = sbuf; *sbufp; sbufp++)
> +    *sbufp = ascii_tolower (*sbufp);
>  
>    if ((i = mutt_getvaluebyname (sbuf, UrlMap)) == -1)
>      return U_UNKNOWN;
> @@ -292,7 +293,8 @@ static int url_mailto_header_allowed (const char *header)
>  
>  int url_parse_mailto (ENVELOPE *e, char **body, const char *src)
>  {
> -  char *t, *p;
> +  const char *t;
> +  char *p;
>    char *tmp;
>    char *headers;
>    char *tag, *value;
> -- 
> 2.53.0
> 

-- 
<https://www.alejandro-colomar.es>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmme8aEACgkQ64mZXMKQ
wqmpVRAAh6OtvW8XaioGK17w02rcvhMzal+NqqtAshktWjdbas+P0VTJQ8/UstkR
nmFgkwWfEDk19vYTLDufsQTj3yaqRAK1ExAvBIzLo7/u+6Lu8rQy4criahXR1ERG
ggVyFvTRv1nS3tVbRPbHTpPxMI8uVTAIZ4gEEKBMw2KyPn1FvFWQY0D+7QsrhowP
kL9qw8nf3B3Um7yKHbGIMJYkTLIqQvU2uXo1yjZcRLj834zULvQ3YNxceUYmZfaG
5jGJDI4V5Lo5kwFtDyJUJ5dRQZtKrMtXThY+mAXyGTgyzHcDRARwFXWXXOwgC8Xc
MrVA4krEv3AKSp4rCIYIPmNo9eqP2J47Olzuuh6xjY+eZ5vsekCtC2/bkOu73kBW
gfNeaHA/yPGou3MmkclsIuvPmnO4dwlJOTlFebaSWHZ+Q0m4UVeP/sYSxYmjX1hV
dbdWbQy368aaUXXkyysR9volvd/CeVGvqcE3dOPpWKGHeeCMoumA1aCPTihWrXwH
aaDoFWyiQ8lfTN9NfR7d8IAayvi4B2W6kWFX906uYCupKya6gjHN79gBKgShJKWx
BbETaL7TI3854UbKs9yr5ZOvRLYF8HkRvjaOKLtMYK29kq+d1pyoT9SBlPkzPO9M
dV9YrQ/Xcv8r/ODkeJq+xJ8aXu5TErht//8PCFNdV7TvtidhfBE=
=suv+
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.