]> git.ipfire.org Git - thirdparty/git.git/commit
remote-curl: avoid assigning string constant to non-const variable
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Jun 2024 06:39:03 +0000 (08:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:30:53 +0000 (10:30 -0700)
commita3da6948c3b6c272bf7a381b86df9a60bdf2b052
tree46e9d2f2133e5958dc3c4f2a9d1dd94fe5565b22
parent5bd0851d97be732470eab8cb8d7255c7050ef384
remote-curl: avoid assigning string constant to non-const variable

When processing remote options, we split the option line into two by
searching for a space. If there is one, we replace the space with '\0',
otherwise we implicitly assume that the value is "true" and thus assign
a string constant.

As the return value of strchr(3P) weirdly enough is a `char *` even
though it gets a `const char *` as input, the assigned-to variable also
is a non-constant. This is fine though because the argument is in fact
an allocated string, and thus we are allowed to modify it. But this will
break once we enable `-Wwrite-strings`.

Refactor the code stop splitting the fields with '\0' altogether.
Instead, we can pass the length of the option name to `set_option()` and
then use strncmp(3P) instead of strcmp(3P).

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