diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-06-07 08:38:49 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-06-07 19:30:53 +0200 |
commit | 8d3a7ce441422f4b48f14c19a1b3be4ba7bfd30f (patch) | |
tree | 5a3360fa0b33605b7cba9a2e78b5e802fc06ccbf /http.c | |
parent | compat/win32: fix const-correctness with string constants (diff) | |
download | git-8d3a7ce441422f4b48f14c19a1b3be4ba7bfd30f.tar.xz git-8d3a7ce441422f4b48f14c19a1b3be4ba7bfd30f.zip |
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>
Diffstat (limited to 'http.c')
-rw-r--r-- | http.c | 5 |
1 files changed, 2 insertions, 3 deletions
@@ -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); } |