I'm pretty sure that it's a new feature in the compiler that detects if the
result of a function returning a pointer to a string was saved into
non-constant pointer from const pointer. This seems reasonable and it seems
like consts were misused in those places.

[[[
[39/469] Building C object
CMakeFiles/libsvn_subr.dir/subversion/libsvn_subr/gpg_agent.c.o
/home/tima/dev/svn-trunk/subversion/libsvn_subr/gpg_agent.c: In function
‘find_running_gpg_agent’:
/home/tima/dev/svn-trunk/subversion/libsvn_subr/gpg_agent.c:391:6: warning:
assignment discards ‘const’ qualifier from pointer target type
[-Wdiscarded-qualifiers]
  391 |   ep = strchr(p, '\n');
      |      ^
[85/469] Building C object
CMakeFiles/libsvn_subr.dir/subversion/libsvn_subr/subst.c.o
/home/tima/dev/svn-trunk/subversion/libsvn_subr/subst.c: In function
‘build_keywords’:
/home/tima/dev/svn-trunk/subversion/libsvn_subr/subst.c:309:15: warning:
assignment discards ‘const’ qualifier from pointer target type
[-Wdiscarded-qualifiers]
  309 |           sep = strchr(keyword, '=');
      |               ^
[93/469] Building C object
CMakeFiles/libsvn_subr.dir/subversion/libsvn_subr/version.c.o
/home/tima/dev/svn-trunk/subversion/libsvn_subr/version.c: In function
‘svn_version__parse_version_string’:
/home/tima/dev/svn-trunk/subversion/libsvn_subr/version.c:257:22: warning:
initialization discards ‘const’ qualifier from pointer target type
[-Wdiscarded-qualifiers]
  257 |       char *hyphen = strchr(piece, '-');
      |                      ^~~~~~
[144/469] Building C object
CMakeFiles/libsvn_fs_fs.dir/subversion/libsvn_fs_fs/tree.c.o
/home/tima/dev/svn-trunk/subversion/libsvn_fs_fs/tree.c: In function
‘check_newline’:
/home/tima/dev/svn-trunk/subversion/libsvn_fs_fs/tree.c:2488:13: warning:
initialization discards ‘const’ qualifier from pointer target type
[-Wdiscarded-qualifiers]
 2488 |   char *c = strchr(path, '\n');
      |             ^~~~~~
[190/469] Building C object
CMakeFiles/libsvn_fs.dir/subversion/libsvn_fs/fs-loader.c.o
/home/tima/dev/svn-trunk/subversion/libsvn_fs/fs-loader.c: In function
‘svn_fs__path_valid’:
/home/tima/dev/svn-trunk/subversion/libsvn_fs/fs-loader.c:493:5: warning:
assignment discards ‘const’ qualifier from pointer target type
[-Wdiscarded-qualifiers]
  493 |   c = strchr(path, '\n');
      |     ^
[226/469] Building C object
CMakeFiles/libsvn_diff.dir/subversion/libsvn_diff/parse-diff.c.o
/home/tima/dev/svn-trunk/subversion/libsvn_diff/parse-diff.c: In function
‘git_start’:
/home/tima/dev/svn-trunk/subversion/libsvn_diff/parse-diff.c:1582:19:
warning: assignment discards ‘const’ qualifier from pointer target type
[-Wdiscarded-qualifiers]
 1582 |   new_path_marker = strstr(old_path_marker, " b/");
      |                   ^
/home/tima/dev/svn-trunk/subversion/libsvn_diff/parse-diff.c:1610:23:
warning: assignment discards ‘const’ qualifier from pointer target type
[-Wdiscarded-qualifiers]
 1610 |       new_path_marker = strstr(new_path_start, " b/");
      |                       ^
]]]

I prepared a patch that fixes them by adding const where needed. Can anyone
correct me if I'm misunderstanding something?

--
Timofei Zhakov
Index: subversion/libsvn_diff/parse-diff.c
===================================================================
--- subversion/libsvn_diff/parse-diff.c (revision 1932024)
+++ subversion/libsvn_diff/parse-diff.c (working copy)
@@ -1545,12 +1545,12 @@ static svn_error_t *
 git_start(enum parse_state *new_state, char *line, svn_patch_t *patch,
           apr_pool_t *result_pool, apr_pool_t *scratch_pool)
 {
-  const char *old_path_start;
+  char *old_path_start;
   char *old_path_end;
-  const char *new_path_start;
-  const char *new_path_end;
+  char *new_path_start;
+  char *new_path_end;
   char *new_path_marker;
-  const char *old_path_marker;
+  char *old_path_marker;
 
   /* ### Add handling of escaped paths
    * http://www.kernel.org/pub/software/scm/git/docs/git-diff.html:
Index: subversion/libsvn_fs/fs-loader.c
===================================================================
--- subversion/libsvn_fs/fs-loader.c    (revision 1932024)
+++ subversion/libsvn_fs/fs-loader.c    (working copy)
@@ -468,7 +468,7 @@ default_warning_func(void *baton, svn_error_t *err
 svn_error_t *
 svn_fs__path_valid(const char *path, apr_pool_t *pool)
 {
-  char *c;
+  const char *c;
 
   /* UTF-8 encoded string without NULs. */
   if (! svn_utf__cstring_is_valid(path))
Index: subversion/libsvn_fs_fs/tree.c
===================================================================
--- subversion/libsvn_fs_fs/tree.c      (revision 1932024)
+++ subversion/libsvn_fs_fs/tree.c      (working copy)
@@ -2485,7 +2485,7 @@ fs_dir_optimal_order(apr_array_header_t **ordered_
 static svn_error_t *
 check_newline(const char *path, apr_pool_t *pool)
 {
-  char *c = strchr(path, '\n');
+  const char *c = strchr(path, '\n');
 
   if (c)
     return svn_error_createf(SVN_ERR_FS_PATH_SYNTAX, NULL,
Index: subversion/libsvn_subr/gpg_agent.c
===================================================================
--- subversion/libsvn_subr/gpg_agent.c  (revision 1932024)
+++ subversion/libsvn_subr/gpg_agent.c  (working copy)
@@ -326,7 +326,7 @@ find_running_gpg_agent(int *new_sd, apr_pool_t *po
   char *buffer;
   const char *socket_name = find_gpg_agent_socket(pool, pool);
   const char *request = NULL;
-  const char *p = NULL;
+  char *p = NULL;
   char *ep = NULL;
   int sd;
 
Index: subversion/libsvn_subr/subst.c
===================================================================
--- subversion/libsvn_subr/subst.c      (revision 1932024)
+++ subversion/libsvn_subr/subst.c      (working copy)
@@ -298,7 +298,7 @@ build_keywords(apr_hash_t **kw,
 
   for (i = 0; i < keyword_tokens->nelts; ++i)
     {
-      const char *keyword = APR_ARRAY_IDX(keyword_tokens, i, const char *);
+      char *keyword = APR_ARRAY_IDX(keyword_tokens, i, char *);
       const char *custom_fmt = NULL;
 
       if (expand_custom_keywords)
Index: subversion/libsvn_subr/version.c
===================================================================
--- subversion/libsvn_subr/version.c    (revision 1932024)
+++ subversion/libsvn_subr/version.c    (working copy)
@@ -253,7 +253,7 @@ svn_version__parse_version_string(svn_version_t **
      require that it be present. */
   if (pieces->nelts == 3)
     {
-      const char *piece = APR_ARRAY_IDX(pieces, 2, const char *);
+      char *piece = APR_ARRAY_IDX(pieces, 2, char *);
       char *hyphen = strchr(piece, '-');
       if (hyphen)
         {

Reply via email to