]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/rebase: always store allocated string in `options.strategy`
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Jun 2024 06:39:31 +0000 (08:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:30:55 +0000 (10:30 -0700)
commitfc066767662ead1b279a20545ff02ab17d835f34
tree3c9da338bf4bc03afd96d6a59de4f76f2b45d527
parent25a47ffac0c50d3bae4058e6327c7bd799240df9
builtin/rebase: always store allocated string in `options.strategy`

The `struct rebase_options::strategy` field is a `char *`, but we do end
up assigning string constants to it in two cases:

  - When being passed a `--strategy=` option via the command line.

  - When being passed a strategy option via `--strategy-option=`, but
    not a strategy.

This will cause warnings once we enable `-Wwrite-strings`.

Ideally, we'd just convert the field to be a `const char *`. But we also
assign to this field via the GIT_TEST_MERGE_ALGORITHM envvar, which we
have to strdup(3P) into it.

Instead, refactor the code to make sure that we only ever assign
allocated strings to this field.

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