Skip to content

Commit 21c57ef

Browse files
peffgitster
authored andcommitted
run-command: explicitly cast away constness when assigning to void
We do this: char *equals = strchr(*e, '='); which implicitly removes the constness from "*e" and cause the compiler to complain. We never write to "equals", but later assign it to a string_list util field, which is defined as non-const "void *". We have to cast somewhere, but doing so at the assignment to util is the least-bad place, since that is the source of the confusion. Sadly we are still open to accidentally writing to the string via the util pointer, but that is the cost of using void pointers, which lose all type information. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 031d29d commit 21c57ef

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

run-command.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,11 @@ static void trace_add_env(struct strbuf *dst, const char *const *deltaenv)
604604
/* Last one wins, see run-command.c:prep_childenv() for context */
605605
for (e = deltaenv; e && *e; e++) {
606606
struct strbuf key = STRBUF_INIT;
607-
char *equals = strchr(*e, '=');
607+
const char *equals = strchr(*e, '=');
608608

609609
if (equals) {
610610
strbuf_add(&key, *e, equals - *e);
611-
string_list_insert(&envs, key.buf)->util = equals + 1;
611+
string_list_insert(&envs, key.buf)->util = (void *)(equals + 1);
612612
} else {
613613
string_list_insert(&envs, *e)->util = NULL;
614614
}

0 commit comments

Comments
 (0)