Re: [PATCH 6/6] Use Arch instead of Debian for sr.ht builds

Alejandro Colomar via Mutt-dev <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <aZ2h6rjtvRsP63x2@devuan>
On 2026-02-24T14:00:39+0100, Alejandro Colomar wrote:
> On 2026-02-24T13:56:23+0100, Alejandro Colomar wrote:
> > Hi Rene,
> > 
> > On 2026-02-24T13:41:26+0100, Rene Kita wrote:
> > > This explains why it went so smooth with Arch. m-(
> > > 
> > > Running the build on Arch I get multiple errors of this kind:
> > > browser.c:548:17: error: initialization discards 'const' qualifier from
> > > pointer target type [-Werror=discarded-qualifiers]
> > >   548 |       char *c = strrchr (d, '/');
> > >       |                 ^~~~~~~
> > > 
> > > This is in function:
> > > static int examine_directory (MUTTMENU *menu, struct browser_state *state,
> > > 			      const char *d, const char *prefix).
> > > 
> > > AFAIU, strrchr is defined as: char * strrchr(const char *s, int c).
> > 
> > Being Arch, I suspect you're using the latest glibc.  C23 has changed
> > the prototype of string search functions to use 'QChar', which is just
> > a way of saying "the const qualifier, if present on the input, is
> > preserved in the output".
> > <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf#subsubsection.7.26.5.6>
> > 
> > This makes it possible to write code that is more type-safe.
> > 
> > Since C23, the standard prototype for strrchr(3) is:
> > 
> > 	QChar *strrchr(QChar *s, int c);
> > 
> > which could be documented in a more C++-style way, with overloads:
> > 
> > 	char *strrchr(char *s, int c);
> > 	const char *strrchr(const char *s, int c);
> > 
> > I now need to update the manual pages, and think I'm going to use the
> > latter, although feel free to suggest some preference or some other way
> > to document it.
> > 
> > The glibc commit that changed this was:
> > 
> > 	glibc.git cd748a63ab1a (2025-11-20; "Implement C23 const-preserving standard library macros")
> > 
> > which is contained in glibc-2.43.
> > 
> > > 
> > > *c is changed later in that function, so we can't make it const. Any
> > > ideas what's the best way forward from here?
> > 
> > If *c is later changed, and it derives from d, then d must be non-const,
> > doesn't it?  Or is c later derived from another pointer?  If the latter
> > is true, then we'd need to use a different local pointer variable.
> 
> After reading the source code myself, this looks like a bug.  d should
> be non-const, as we modify it.
> 
> 	$ grepc examine_directory . | grep -e '\<d\>' -e '\<c\>' -e { -e };
> 	./browser.c:static int examine_directory (MUTTMENU *menu, struct browser_state *state,
> 				      const char *d, const char *prefix)

I've tried fixing this, by trying to remove const from above.  However,
that triggers a number of warnings like this one:

	buffer.h:32:54: warning: passing argument 3 of ‘examine_directory’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
	   32 | #define mutt_b2s(b) (b->data ? (const char *)b->data : "")
	      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
	browser.c:947:44: note: in expansion of macro ‘mutt_b2s’
	  947 |       if (examine_directory (NULL, &state, mutt_b2s (working_dir), mutt_b2s (prefix)) == -1)
	      |                                            ^~~~~~~~
	browser.c:535:37: note: expected ‘char *’ but argument is of type ‘const char *’
	  535 |                               char *d, const char *prefix)
	      |                               ~~~~~~^

The solution would be to make that "" modifiable, with a C99 compound
literal.  We require C99, so we can do that.  However, that would mean:

	-#define mutt_b2s(b) (b->data ? (const char *)b->data : "")
	+#define mutt_b2s(b) (b->data ? b->data : (char []){""})

which itself carries questions: is it okay to modify such a buffer?
It must be okay, since we're already doing it, but still needs some
research.  Also, why was const added there in the first place, if we're
modifying it?


Cheers,
Alex

> 	{
> 	  while (stat (d, &s) == -1)
> 	  {
> 	    {
> 	      char *c = strrchr (d, '/');
> 	      if (c && (c > d))
> 	      {
> 		*c = 0;
> 	      }
> 	    }
> 	    mutt_perror (d);
> 	  }
> 	  {
> 	    mutt_error (_("%s is not a directory."), d);
> 	  }
> 	  if ((dp = opendir (d)) == NULL)
> 	  {
> 	    mutt_perror (d);
> 	  }
> 	  {
> 	    mutt_buffer_concat_path (full_path, d, de->d_name);
> 	    {
> 	    }
> 	  }
> 	}
> 
> > 
> > 
> > Have a lovely day!
> > Alex
> > 
> > -- 
> > <https://www.alejandro-colomar.es>
> 
> 
> 
> -- 
> <https://www.alejandro-colomar.es>



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

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmmdow4ACgkQ64mZXMKQ
wqnoPg//bzjsGoTOPGiZv7HN2qmB7VLmLh4coPQj2T23bPIDOcNBFWjWCFKkETYU
uBlID9V71G2NPfwKud1zIf3MIksf7zP2sKKkBbFrqrgK2P1Z3dTotxVIFBHzQFJ8
qVKSgrL0t2AYw+AUKS38WwBip60MyPHjj1KpseKn6BkMD7cpSJlGaDS0k6ZWABbj
27UGFlucgA5+f4KATZ4UnxJglImDLezBWni2H9QokER/uV9yq2YEYDTrE3R11S1F
VlFCUBI8lEHMKISY2LFkT57t5iatKR1VbsODDKV/4CGgcsWiM5cJHhI/C4Y2kLCE
L5bmcFQ6IwkyBtNHdyDL7DQ30LonJEB16bwr4KeZdEdJOk3HYMaRYOpVI1H18ebT
YVojgeGHiZ3KVTnv2v52tmpp0H5O7b/VX4MDg5njWA4uvnivqMO43gsa2wXaSmzK
W7i5pl/ohPrFkj8M/RH/UFxa3uOqGFAX1Qy7VAncONqqN/MEWJReIz3Dfgo4lM+d
DF3wmgOYXjumjN6I/SiZslY3/kA90/f8gpj0muHhAB54alA0AX1Br1M00+SxdVPE
I6OrepypYKldGK0uJd+XIndKPM0YSyqYPmgElTg2r127YQWK+/G4mB6WNj/pBQGP
4p6WKfmFavfnzZZ3vHAaEvBq/IvB3gjH8cTldKNxpEAw/8M8Mc0=
=Fc/0
-----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.