http: do not assign string constant to non-const field
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>
Patrick Steinhardt committed
Jun 7, 2024 at 08:38 UTC
8d3a7ce441422f4b48f14c19a1b3be4ba7bfd30f
1 file changed
+2
-3
http.c
+2
-3
@@ -1974,7 +1974,7 @@ static void write_accept_language(struct strbuf *buf)
1974
1975
/* add '*' */
1976
REALLOC_ARRAY(language_tags, num_langs + 1);
1977
- language_tags[num_langs++] = "*"; /* it's OK; this won't be freed */
1977
+ language_tags[num_langs++] = xstrdup("*");
1978
1979
/* compute decimal_places */
1980
for (max_q = 1, decimal_places = 0;
@@ -2004,8 +2004,7 @@ static void write_accept_language(struct strbuf *buf)
2004
}
2005
}
2006
2007
- /* free language tags -- last one is a static '*' */
2008
- for (i = 0; i < num_langs - 1; i++)
2007
+ for (i = 0; i < num_langs; i++)
2008
free(language_tags[i]);
2009
free(language_tags);
2010
}