This is an automated email from Gerrit.

"Marian Buschsieweke <[email protected]>" just uploaded a new patch 
set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9721

-- gerrit

commit dc4bd94ea8b2a6569e6a4d0689543ff48b03414b
Author: Marian Buschsieweke <[email protected]>
Date:   Thu May 28 18:08:57 2026 +0200

    tree-wide: fix compilation with modern glibc
    
    Recently glibc added some clever macro trickery with the effect that
    
            char *strchr(const char *s, int c);
    
    behaves now, depending on the `const`ness of the first argument, as
    either:
    
            const char *strchr(const char *s, int c);
    
    or:
    
            char *strchr(char *s, int c);
    
    The intend is that one does not accidentally turn a `const char *` into
    a `char *`. This change results in compilations errors such as:
    
            src/helper/options.c: In function ‘find_relative_path’:
            src/helper/options.c:154:30: error: initialization discards ‘const’ 
qualifier from pointer target type [-Werror=discarded-qualifiers]
              154 |                 char *next = strchr(from, '/');
                  |                              ^~~~~~
    
    This commit fixes these compilation errors. In most cases just adding
    a `const` the variable storing the return value was sufficient. In once
    case, modifying the `CMD_ARGV[0]` in-place to split host and port
    (separated by `:`) was changed by instead just copying up to the `:`
    instead.
    
    Change-Id: I46c659f00039b2161cf3fc2e9473f998ab63ed92
    Signed-off-by: Marian Buschsieweke <[email protected]>

diff --git a/src/helper/log.c b/src/helper/log.c
index ce21a907d3..8263cfc601 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -104,7 +104,7 @@ static void log_puts(enum log_levels level,
        const char *function,
        const char *string)
 {
-       char *f;
+       const char *f;
 
        if (!log_output) {
                /* log_init() not called yet; print on stderr */
diff --git a/src/helper/options.c b/src/helper/options.c
index 28e2221717..9eb26a4762 100644
--- a/src/helper/options.c
+++ b/src/helper/options.c
@@ -151,7 +151,7 @@ static char *find_relative_path(const char *from, const 
char *to)
        while (from[0] != '\0') {
                if (from[0] != '/')
                        i++;
-               char *next = strchr(from, '/');
+               const char *next = strchr(from, '/');
                if (!next)
                        break;
                from = next + 1;
diff --git a/src/jtag/drivers/vdebug.c b/src/jtag/drivers/vdebug.c
index 29bfa8360d..5973fc2a9f 100644
--- a/src/jtag/drivers/vdebug.c
+++ b/src/jtag/drivers/vdebug.c
@@ -1218,9 +1218,13 @@ COMMAND_HANDLER(vdebug_set_server)
        if ((CMD_ARGC != 1) || !strchr(CMD_ARGV[0], ':'))
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       char *pchar = strchr(CMD_ARGV[0], ':');
-       *pchar = '\0';
-       strncpy(vdc.server_name, CMD_ARGV[0], sizeof(vdc.server_name) - 1);
+       const char *pchar = strchr(CMD_ARGV[0], ':');
+       size_t len = (size_t)(pchar - CMD_ARGV[0]);
+       /* clamp len to not exceed available space */
+       len = (len < sizeof(vdc.server_name) - 1) ? len : 
sizeof(vdc.server_name) - 1;
+       memcpy(vdc.server_name, CMD_ARGV[0], len);
+       vdc.server_name[len] = '\0';
+
        int port = atoi(++pchar);
        if (port < 0 || port > UINT16_MAX) {
                LOG_ERROR("invalid port number %d specified", port);
diff --git a/src/rtos/ecos.c b/src/rtos/ecos.c
index 120b50685e..cadfa4442d 100644
--- a/src/rtos/ecos.c
+++ b/src/rtos/ecos.c
@@ -510,7 +510,7 @@ static bool ecos_escape_string(const char *raw, char *out, 
size_t limit)
                        continue;
                }
 
-               char *fidx = strchr(tokens, *raw);
+               const char *fidx = strchr(tokens, *raw);
                if (!fidx) {
                        /* Should never happen assuming xmlchars
                         * vector and tokens string match. */
diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c
index 83d50c2d0b..52115a529d 100644
--- a/src/server/telnet_server.c
+++ b/src/server/telnet_server.c
@@ -68,7 +68,7 @@ static int telnet_outputline(struct connection *connection, 
const char *line)
 
        /* process lines in buffer */
        while (*line) {
-               char *line_end = strchr(line, '\n');
+               const char *line_end = strchr(line, '\n');
 
                if (line_end)
                        len = line_end-line;

-- 

Reply via email to