All of lore.kernel.org
 help / color / mirror / Atom feed
From: bugzilla-daemon@kernel.org
To: linux-man@vger.kernel.org
Subject: [Bug 221533] strstr/c23/constness
Date: Sat, 16 May 2026 16:57:41 +0000	[thread overview]
Message-ID: <bug-221533-11311-aO63pl4r9F@https.bugzilla.kernel.org/> (raw)
In-Reply-To: <bug-221533-11311@https.bugzilla.kernel.org/>

https://bugzilla.kernel.org/show_bug.cgi?id=221533

--- Comment #1 from Alejandro Colomar (alx@kernel.org) ---
Hi,

On 2026-05-16T16:47:42+0000, bugzilla-daemon@kernel.org wrote:
> Hi,
>   In C23 strstr can return a const char* if the first parameter is a const
> char*;  this is also true of a bunch of the other routines.
> 
>   I'm not really sure how this should be documented, I guess two entries for
> each function with some note saying it's only C23 and later?

I've been thinking about this.  At the moment, I've documented one
function that has this property: strnul(3) (which is a gnulib extension,
not part of C23).  There, I've used C++-style, documenting it with two
prototypes, as if it were a function overload.  I think we should do the
same for the C23 const-preserving macros.

        SYNOPSIS
             #include <string.h>

             char *strnul(char *s);
             const char *strnul(const char *s);

I'll work on some patches for the C23 APIs.

> See:
>
> https://sourceware.org/cgit/glibc/commit/string/string.h?id=cd748a63ab1a7ae846175c532a3daab341c62690
> 
> for the glibc change that implemented it.
> 
> It can break some existing code, e.g. something like:

Indeed, it broke mutt(1), for example.  That allowed finding a few bugs
in mutt(1), which were modifying read-only strings.  Most of the cases
were false positives, though, which could be fixed easily by adding
const.

> int foo(const char *a)
> {
>    char *bar = strstr(a, "frog");
> }
> 
> gives:
> t.c:9:16: warning: initialization discards ‘const’ qualifier from pointer
> target type [-Wdiscarded-qualifiers]
>     9 |    char *bar = strstr(a, "frog");
>       |                ^~~~~~

Yup.


Have a lovely day!
Alex

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.

  reply	other threads:[~2026-05-16 16:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-16 16:47 [Bug 221533] New: strstr/c23/constness bugzilla-daemon
2026-05-16 16:57 ` bugzilla-daemon [this message]
2026-05-16 17:18 ` [Bug 221533] strstr/c23/constness bugzilla-daemon
2026-05-17  7:36 ` bugzilla-daemon

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

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

  git send-email \
    --in-reply-to=bug-221533-11311-aO63pl4r9F@https.bugzilla.kernel.org/ \
    --to=bugzilla-daemon@kernel.org \
    --cc=linux-man@vger.kernel.org \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.