Skip to content

Commit 8d3a7ce

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e7b4019 commit 8d3a7ce

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

http.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ static void write_accept_language(struct strbuf *buf)
19741974

19751975
/* add '*' */
19761976
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("*");
19781978

19791979
/* compute decimal_places */
19801980
for (max_q = 1, decimal_places = 0;
@@ -2004,8 +2004,7 @@ static void write_accept_language(struct strbuf *buf)
20042004
}
20052005
}
20062006

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++)
20092008
free(language_tags[i]);
20102009
free(language_tags);
20112010
}

0 commit comments

Comments
 (0)