Re: [PATCH] alias.c: use git_config_string() to get alias_val
- From
Stephan Beyer <s-beyer@gmx.net>
- Date
- Apr 5, 2008, 17:39 UTC
- Message-ID
- <20080405173956.GD14565@leksak.fem-net>
- In-Reply-To
- <200804051819.46904.chriscool@tuxfamily.org>
Hi,
Show 6 quoted lines
> Did you see: > > "(And no, casting the "char **" into a "const char **" is not a good > solution either.)" > > in the above page ?
Yes.
Show 5 quoted lines
> > + if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) > > + return git_config_string((const char**)&alias_val, k, v); > > Are you sure this ugly cast to "const char**" is needed ? > Isn't there a better way to do it ?
Well, because alias_val is not a constant[1], changing static char *alias_val; to static const char *alias_val; is not an option.
The only other way I see[2] atm is a brain-damaged:
--
static int alias_lookup_cb(const char *k, const char *v)
{
if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) {
const char *tmp;
int ret = git_config_string(&tmp, k, v);
alias_val = xstrdup(tmp);
/* actually, tmp should be free()'d. */
return ret;
}
return 0;
}
--
But instead of doing that, the original should be kept, because it is
better in code beauty, performance and memory usage. ;-)So I thought the casting is ugly, but it does no harm. I hope ;) (Yes, a cast from const char ** to char ** is, indeed, dangerous.)
But if I miss an obvious point, please tell me :)
Regards, Stephan
Footnotes:
[1] It is no constant because it is returned by alias_lookup(),
and thus could be changed by further instructions.
[2] ...between the many ways that result in compiler warnings ;-)-- Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F