]> git.ipfire.org Git - thirdparty/git.git/commitdiff
http: do not assign string constant to non-const field
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Jun 2024 06:38:49 +0000 (08:38 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:30:53 +0000 (10:30 -0700)
In `write_accept_language()`, we put all acceptable languages into an
array. While all entries in that array are allocated strings, the final
entry in that array is a string constant. This is fine because we
explicitly skip over the last entry when freeing the array, but will
cause warnings once we enable `-Wwrite-strings`.

Adapt the code to also allocate the final entry.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
http.c

diff --git a/http.c b/http.c
index 67cc47d28faa47ea024a205d65405400ca94703a..2dea2d03da74b3194b14f8cb11d061b2ba72a7cb 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1974,7 +1974,7 @@ static void write_accept_language(struct strbuf *buf)
 
                /* add '*' */
                REALLOC_ARRAY(language_tags, num_langs + 1);
-               language_tags[num_langs++] = "*"; /* it's OK; this won't be freed */
+               language_tags[num_langs++] = xstrdup("*");
 
                /* compute decimal_places */
                for (max_q = 1, decimal_places = 0;
@@ -2004,8 +2004,7 @@ static void write_accept_language(struct strbuf *buf)
                }
        }
 
-       /* free language tags -- last one is a static '*' */
-       for (i = 0; i < num_langs - 1; i++)
+       for (i = 0; i < num_langs; i++)
                free(language_tags[i]);
        free(language_tags);
 }