RFR: 8378180: Compiling OpenJDK with C23 C-Compiler gives warning: initialization discards ‘const’ qualifier from pointer target type
Hi all, this is a quick patch to fix a build issue I encountered when updating my Linux system. [Glibc 2.43](https://lists.gnu.org/archive/html/info-gnu/2026-01/msg00005.html) changes the definition of some string related functions to return `const char*` when provided a `const char*` parameter, rather than the previous behavior of returning `char*`. I've fixed this by applying the `const` modifier, and casting to `char*` when needed. This should be backwards-compatible since assigning a non-const pointer to const is an implicit conversion. Thoughts and comments would be appreciated on whether this is the best way to fix this issue. Thanks! ------------- Commit messages: - Fix discarded const qualifiers Changes: https://git.openjdk.org/jdk/pull/29929/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29929&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8378180 Stats: 18 lines in 9 files changed: 0 ins; 0 del; 18 mod Patch: https://git.openjdk.org/jdk/pull/29929.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/29929/head:pull/29929 PR: https://git.openjdk.org/jdk/pull/29929
On Thu, 26 Feb 2026 04:26:43 GMT, Jasmine Karthikeyan <jkarthikeyan@openjdk.org> wrote:
Hi all, this is a quick patch to fix a build issue I encountered when updating my Linux system. [Glibc 2.43](https://lists.gnu.org/archive/html/info-gnu/2026-01/msg00005.html) changes the definition of some string related functions to return `const char*` when provided a `const char*` parameter, rather than the previous behavior of returning `char*`. I've fixed this by applying the `const` modifier, and casting to `char*` when needed. This should be backwards-compatible since assigning a non-const pointer to const is an implicit conversion. Thoughts and comments would be appreciated on whether this is the best way to fix this issue. Thanks!
src/java.base/unix/native/libjava/TimeZone_md.c line 98:
96: static const char *zidir = "zoneinfo/"; 97: 98: char* pos = (char*) strstr((const char *)str, zidir);
Suggestion: char *pos = strstr(str, zidir); removing the first cast should also work here ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29929#discussion_r2859514812
On Thu, 26 Feb 2026 04:26:43 GMT, Jasmine Karthikeyan <jkarthikeyan@openjdk.org> wrote:
Hi all, this is a quick patch to fix a build issue I encountered when updating my Linux system. [Glibc 2.43](https://lists.gnu.org/archive/html/info-gnu/2026-01/msg00005.html) changes the definition of some string related functions to return `const char*` when provided a `const char*` parameter, rather than the previous behavior of returning `char*`. I've fixed this by applying the `const` modifier, and casting to `char*` when needed. This should be backwards-compatible since assigning a non-const pointer to const is an implicit conversion. Thoughts and comments would be appreciated on whether this is the best way to fix this issue. Thanks!
src/jdk.jpackage/linux/native/applauncher/LinuxPackage.c line 230:
228: 229: static int initDebPackage(void* desc, const char* str) { 230: char* colonChrPos = (char*) strchr(str, ':');
`str` should really be `char*` instead; it's modified in line 232 below. Once you change `str`'s type, you will no longer need a cast here. You'll also need to modify the `popenCallbackType` type to remove `const`. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29929#discussion_r2872329859
participants (3)
-
Daniel Jeliński
-
Jasmine Karthikeyan
-
Luca Kellermann