* [PATCH 0/3] C23 string func() handling updates
@ 2026-02-14 0:18 Nicholas Vinson
2026-02-14 0:18 ` [PATCH 1/3] grub-core/osdep/linux/ofpath.c: Update strstr() calls Nicholas Vinson
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Nicholas Vinson @ 2026-02-14 0:18 UTC (permalink / raw)
To: grub-devel, dkiper; +Cc: Nicholas Vinson
With C23, the following 12 functions were updated to have 'const-aware'
return types:
bsearch(), bsearch_s(), memchr(), strchr(), strpbrk(), strrchr(),
strstr(), wcschr(), wcspbrk(), wcsrchr(), wcsstr(), and wmemchr().
Of these functions, strchr(), strpbrk(), strrchr(), and strstr(), are
used within GRUB, and for 3 of these functions, strchr(), strrchr(), and
strstr(), some of their calls within GRUB are now resulting in
compile-time errors due to the C23 changes and 'discarding qualifier'
errors. The errors are generated by elevating 'discarding qualifier'
warnings to error-level. A promotion GRUB's build system defaults to
doing.
Most of the changes this patch series makes to fix these errors are
simple and only requiring changing a variable's type from 'char *' to
'const char *'. However, the changes in ofpath.c are more involved as
they also update the way lengths are calculated and *printf() functions
are called as a result of these C23 changes.
Furthermore, the changes are needed as C runtime libraries, notably
glbc starting with version 2.43, are implementing the changes the C23
standard requires.
Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Nicholas Vinson (3):
grub-core/osdep/linux/ofpath.c: Update strstr() calls
util/probe.c: save strrchr() ret val to const data ptr.
util/resolve.c: Save str[r]chr() ret val to const data ptr
grub-core/osdep/linux/ofpath.c | 25 ++++++++++++-------------
util/probe.c | 6 +++---
util/resolve.c | 10 +++++-----
3 files changed, 20 insertions(+), 21 deletions(-)
--
2.53.0
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 1/3] grub-core/osdep/linux/ofpath.c: Update strstr() calls 2026-02-14 0:18 [PATCH 0/3] C23 string func() handling updates Nicholas Vinson @ 2026-02-14 0:18 ` Nicholas Vinson 2026-02-16 16:54 ` Daniel Kiper 2026-02-14 0:18 ` [PATCH 2/3] util/probe.c: save strrchr() ret val to const data ptr Nicholas Vinson 2026-02-14 0:18 ` [PATCH 3/3] util/resolve.c: Save str[r]chr() " Nicholas Vinson 2 siblings, 1 reply; 8+ messages in thread From: Nicholas Vinson @ 2026-02-14 0:18 UTC (permalink / raw) To: grub-devel, dkiper; +Cc: Nicholas Vinson With C23, strstr() returns a 'const char *' if its first agrument is 'const char *', and these changes are implemented in glibc-2.43. As a result, the first strstr() call in check_sas() now returns a 'const char *' instead of 'char *' because sysfs_path is a 'const char *'. This triggers a "discards qualifiers" warning, that is later promoted to an error and ultimately causes the build to fail. To fix the issue, this patch converts 'ed', the pointer that stores strstr()'s return value, to a 'const char *'. Removes the xstrdup() call and cleans up the rest of the function by updating the *printf() calls and using pointer arthimetic to compute lengths instead of strlen(). Signed-off-by: Nicholas Vinson <nvinson234@gmail.com> --- grub-core/osdep/linux/ofpath.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c index 24a4d5c8d..8dd311651 100644 --- a/grub-core/osdep/linux/ofpath.c +++ b/grub-core/osdep/linux/ofpath.c @@ -488,8 +488,11 @@ check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id) static void check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address) { - char *ed = strstr (sysfs_path, "end_device"); - char *p, *q, *path; + const char *ed = strstr (sysfs_path, "end_device"); + int p_len; + int ed_len; + const char *q; + char *path; char phy[21]; int fd; size_t path_size; @@ -498,20 +501,16 @@ check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address) return; /* SAS devices are identified using disk@$PHY_ID */ - p = xstrdup (sysfs_path); - ed = strstr(p, "end_device"); - if (!ed) - return; - q = ed; while (*q && *q != '/') q++; - *q = '\0'; + p_len = (int)(q - sysfs_path); + ed_len = (int)(q - ed); - path_size = (strlen (p) + strlen (ed) - + sizeof ("%s/sas_device/%s/phy_identifier")); + path_size = (p_len + ed_len + sizeof ("/sas_device//phy_identifier")); path = xmalloc (path_size); - snprintf (path, path_size, "%s/sas_device/%s/phy_identifier", p, ed); + snprintf (path, path_size, "%.*s/sas_device/%.*s/phy_identifier", p_len, + sysfs_path, ed_len, ed); fd = open (path, O_RDONLY); if (fd < 0) grub_util_error (_("cannot open `%s': %s"), path, strerror (errno)); @@ -524,7 +523,8 @@ check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address) sscanf (phy, "%d", tgt); - snprintf (path, path_size, "%s/sas_device/%s/sas_address", p, ed); + snprintf (path, path_size, "%.*s/sas_device/%.*s/sas_address", p_len, + sysfs_path, ed_len, ed); fd = open (path, O_RDONLY); if (fd < 0) grub_util_error (_("cannot open `%s': %s"), path, strerror (errno)); @@ -535,7 +535,6 @@ check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address) sscanf (phy, "%lx", sas_address); free (path); - free (p); close (fd); } -- 2.53.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] grub-core/osdep/linux/ofpath.c: Update strstr() calls 2026-02-14 0:18 ` [PATCH 1/3] grub-core/osdep/linux/ofpath.c: Update strstr() calls Nicholas Vinson @ 2026-02-16 16:54 ` Daniel Kiper 2026-02-23 17:46 ` Nicholas Vinson 0 siblings, 1 reply; 8+ messages in thread From: Daniel Kiper @ 2026-02-16 16:54 UTC (permalink / raw) To: Nicholas Vinson; +Cc: grub-devel On Fri, Feb 13, 2026 at 07:18:35PM -0500, Nicholas Vinson wrote: > With C23, strstr() returns a 'const char *' if its first agrument is > 'const char *', and these changes are implemented in glibc-2.43. > > As a result, the first strstr() call in check_sas() now returns a 'const > char *' instead of 'char *' because sysfs_path is a 'const char *'. This > triggers a "discards qualifiers" warning, that is later promoted to an > error and ultimately causes the build to fail. > > To fix the issue, this patch converts 'ed', the pointer that stores > strstr()'s return value, to a 'const char *'. Removes the xstrdup() > call and cleans up the rest of the function by updating the *printf() > calls and using pointer arthimetic to compute lengths instead of > strlen(). > > Signed-off-by: Nicholas Vinson <nvinson234@gmail.com> > --- > grub-core/osdep/linux/ofpath.c | 25 ++++++++++++------------- > 1 file changed, 12 insertions(+), 13 deletions(-) > > diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c > index 24a4d5c8d..8dd311651 100644 > --- a/grub-core/osdep/linux/ofpath.c > +++ b/grub-core/osdep/linux/ofpath.c > @@ -488,8 +488,11 @@ check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id) > static void > check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address) > { > - char *ed = strstr (sysfs_path, "end_device"); > - char *p, *q, *path; > + const char *ed = strstr (sysfs_path, "end_device"); > + int p_len; > + int ed_len; > + const char *q; > + char *path; > char phy[21]; > int fd; > size_t path_size; > @@ -498,20 +501,16 @@ check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address) > return; > > /* SAS devices are identified using disk@$PHY_ID */ > - p = xstrdup (sysfs_path); > - ed = strstr(p, "end_device"); > - if (!ed) > - return; > - > q = ed; You blindly assume the "ed" is not NULL here. It is not true after "if" removal above. > while (*q && *q != '/') > q++; > - *q = '\0'; > + p_len = (int)(q - sysfs_path); > + ed_len = (int)(q - ed); Missing spaces after (int)... > - path_size = (strlen (p) + strlen (ed) > - + sizeof ("%s/sas_device/%s/phy_identifier")); > + path_size = (p_len + ed_len + sizeof ("/sas_device//phy_identifier")); This sizof() change makes sens for me but it has to be reflected in the commit message. Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] grub-core/osdep/linux/ofpath.c: Update strstr() calls 2026-02-16 16:54 ` Daniel Kiper @ 2026-02-23 17:46 ` Nicholas Vinson 0 siblings, 0 replies; 8+ messages in thread From: Nicholas Vinson @ 2026-02-23 17:46 UTC (permalink / raw) To: Daniel Kiper; +Cc: grub-devel On 2/16/26 11:54, Daniel Kiper wrote: > On Fri, Feb 13, 2026 at 07:18:35PM -0500, Nicholas Vinson wrote: >> With C23, strstr() returns a 'const char *' if its first agrument is >> 'const char *', and these changes are implemented in glibc-2.43. >> >> As a result, the first strstr() call in check_sas() now returns a 'const >> char *' instead of 'char *' because sysfs_path is a 'const char *'. This >> triggers a "discards qualifiers" warning, that is later promoted to an >> error and ultimately causes the build to fail. >> >> To fix the issue, this patch converts 'ed', the pointer that stores >> strstr()'s return value, to a 'const char *'. Removes the xstrdup() >> call and cleans up the rest of the function by updating the *printf() >> calls and using pointer arthimetic to compute lengths instead of >> strlen(). >> >> Signed-off-by: Nicholas Vinson <nvinson234@gmail.com> >> --- >> grub-core/osdep/linux/ofpath.c | 25 ++++++++++++------------- >> 1 file changed, 12 insertions(+), 13 deletions(-) >> >> diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c >> index 24a4d5c8d..8dd311651 100644 >> --- a/grub-core/osdep/linux/ofpath.c >> +++ b/grub-core/osdep/linux/ofpath.c >> @@ -488,8 +488,11 @@ check_hba_identifiers (const char *sysfs_path, int *vendor, int *device_id) >> static void >> check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address) >> { >> - char *ed = strstr (sysfs_path, "end_device"); >> - char *p, *q, *path; >> + const char *ed = strstr (sysfs_path, "end_device"); >> + int p_len; >> + int ed_len; >> + const char *q; >> + char *path; >> char phy[21]; >> int fd; >> size_t path_size; >> @@ -498,20 +501,16 @@ check_sas (const char *sysfs_path, int *tgt, unsigned long int *sas_address) >> return; >> >> /* SAS devices are identified using disk@$PHY_ID */ >> - p = xstrdup (sysfs_path); >> - ed = strstr(p, "end_device"); >> - if (!ed) >> - return; >> - >> q = ed; > > You blindly assume the "ed" is not NULL here. It is not true after > "if" removal above. There is a "if (!ed)" check between the "size_t path_size;" and the SAS devices comment. The check is more than 3 lines away from either hunk so it doesn't appear in the diff. > >> while (*q && *q != '/') >> q++; >> - *q = '\0'; >> + p_len = (int)(q - sysfs_path); >> + ed_len = (int)(q - ed); > > Missing spaces after (int)... fixed. > >> - path_size = (strlen (p) + strlen (ed) >> - + sizeof ("%s/sas_device/%s/phy_identifier")); >> + path_size = (p_len + ed_len + sizeof ("/sas_device//phy_identifier")); > > This sizof() change makes sens for me but it has to be reflected in the > commit message. I split this out into its own commit. I'll send an updated patch series within the next day or two. Thanks, Nicholas Vinson > > Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] util/probe.c: save strrchr() ret val to const data ptr. 2026-02-14 0:18 [PATCH 0/3] C23 string func() handling updates Nicholas Vinson 2026-02-14 0:18 ` [PATCH 1/3] grub-core/osdep/linux/ofpath.c: Update strstr() calls Nicholas Vinson @ 2026-02-14 0:18 ` Nicholas Vinson 2026-02-16 16:56 ` Daniel Kiper 2026-02-14 0:18 ` [PATCH 3/3] util/resolve.c: Save str[r]chr() " Nicholas Vinson 2 siblings, 1 reply; 8+ messages in thread From: Nicholas Vinson @ 2026-02-14 0:18 UTC (permalink / raw) To: grub-devel, dkiper; +Cc: Nicholas Vinson With glibc-2.43 implementing the C23 standard, strrchr() now returns 'const char *' when its first agrument is 'const char *'. The fix is update all pointers receiving strrchr()'s return value so that they are now 'const char *' instead of 'char *'. Signed-off-by: Nicholas Vinson <nvinson234@gmail.com> --- util/probe.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/probe.c b/util/probe.c index 81d91cf59..a9158d640 100644 --- a/util/probe.c +++ b/util/probe.c @@ -70,7 +70,7 @@ char * grub_util_guess_bios_drive (const char *orig_path) { char *canon; - char *ptr; + const char *ptr; canon = grub_canonicalize_file_name (orig_path); if (!canon) return NULL; @@ -99,7 +99,7 @@ char * grub_util_guess_efi_drive (const char *orig_path) { char *canon; - char *ptr; + const char *ptr; canon = grub_canonicalize_file_name (orig_path); if (!canon) return NULL; @@ -128,7 +128,7 @@ char * grub_util_guess_baremetal_drive (const char *orig_path) { char *canon; - char *ptr; + const char *ptr; canon = grub_canonicalize_file_name (orig_path); if (!canon) return NULL; -- 2.53.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] util/probe.c: save strrchr() ret val to const data ptr. 2026-02-14 0:18 ` [PATCH 2/3] util/probe.c: save strrchr() ret val to const data ptr Nicholas Vinson @ 2026-02-16 16:56 ` Daniel Kiper 0 siblings, 0 replies; 8+ messages in thread From: Daniel Kiper @ 2026-02-16 16:56 UTC (permalink / raw) To: Nicholas Vinson; +Cc: grub-devel On Fri, Feb 13, 2026 at 07:18:44PM -0500, Nicholas Vinson wrote: > With glibc-2.43 implementing the C23 standard, strrchr() now returns > 'const char *' when its first agrument is 'const char *'. > > The fix is update all pointers receiving strrchr()'s return value so > that they are now 'const char *' instead of 'char *'. > > Signed-off-by: Nicholas Vinson <nvinson234@gmail.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] util/resolve.c: Save str[r]chr() ret val to const data ptr 2026-02-14 0:18 [PATCH 0/3] C23 string func() handling updates Nicholas Vinson 2026-02-14 0:18 ` [PATCH 1/3] grub-core/osdep/linux/ofpath.c: Update strstr() calls Nicholas Vinson 2026-02-14 0:18 ` [PATCH 2/3] util/probe.c: save strrchr() ret val to const data ptr Nicholas Vinson @ 2026-02-14 0:18 ` Nicholas Vinson 2026-02-16 16:58 ` Daniel Kiper 2 siblings, 1 reply; 8+ messages in thread From: Nicholas Vinson @ 2026-02-14 0:18 UTC (permalink / raw) To: grub-devel, dkiper; +Cc: Nicholas Vinson With glibc-2.43 implementing the C23 standard, strrchr() and strchr() now return 'const char *' when its first agrument is 'const char *'. The fix is update all pointers receiving strrchr() and strchr()'s return values so that they are now 'const char *' instead of 'char *'. Signed-off-by: Nicholas Vinson <nvinson234@gmail.com> --- util/resolve.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/resolve.c b/util/resolve.c index b6e26312f..254379195 100644 --- a/util/resolve.c +++ b/util/resolve.c @@ -138,12 +138,12 @@ read_dep_list (FILE *fp) static char * get_module_name (const char *str) { - char *base; - char *ext; + const char *base; + const char *ext; base = strrchr (str, '/'); if (! base) - base = (char *) str; + base = str; else base++; @@ -164,9 +164,9 @@ get_module_name (const char *str) static char * get_module_path (const char *prefix, const char *str) { - char *dir; + const char *dir; char *base; - char *ext; + const char *ext; char *ret; ext = strrchr (str, '.'); -- 2.53.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] util/resolve.c: Save str[r]chr() ret val to const data ptr 2026-02-14 0:18 ` [PATCH 3/3] util/resolve.c: Save str[r]chr() " Nicholas Vinson @ 2026-02-16 16:58 ` Daniel Kiper 0 siblings, 0 replies; 8+ messages in thread From: Daniel Kiper @ 2026-02-16 16:58 UTC (permalink / raw) To: Nicholas Vinson; +Cc: grub-devel On Fri, Feb 13, 2026 at 07:18:50PM -0500, Nicholas Vinson wrote: > With glibc-2.43 implementing the C23 standard, strrchr() and strchr() > now return 'const char *' when its first agrument is 'const char *'. > > The fix is update all pointers receiving strrchr() and strchr()'s return > values so that they are now 'const char *' instead of 'char *'. > > Signed-off-by: Nicholas Vinson <nvinson234@gmail.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-02-23 17:46 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-02-14 0:18 [PATCH 0/3] C23 string func() handling updates Nicholas Vinson 2026-02-14 0:18 ` [PATCH 1/3] grub-core/osdep/linux/ofpath.c: Update strstr() calls Nicholas Vinson 2026-02-16 16:54 ` Daniel Kiper 2026-02-23 17:46 ` Nicholas Vinson 2026-02-14 0:18 ` [PATCH 2/3] util/probe.c: save strrchr() ret val to const data ptr Nicholas Vinson 2026-02-16 16:56 ` Daniel Kiper 2026-02-14 0:18 ` [PATCH 3/3] util/resolve.c: Save str[r]chr() " Nicholas Vinson 2026-02-16 16:58 ` Daniel Kiper
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox