X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=config.c;h=3cae3901aa9b50e8d04a8ce2633a1a1ef8ed0f6c;hb=73bcf53342f16a66ae4e02ed50a08bd34d846bfb;hp=d9f2b787b94f2506ff7842c1b7b06bd15342ba6f;hpb=b17fda5c07744190e2f9caa24321596830064083;p=git.git diff --git a/config.c b/config.c index d9f2b787b..3cae3901a 100644 --- a/config.c +++ b/config.c @@ -103,6 +103,11 @@ static char *parse_value(void) } } +static inline int iskeychar(int c) +{ + return isalnum(c) || c == '-'; +} + static int get_value(config_fn_t fn, char *name, unsigned int len) { int c; @@ -113,7 +118,7 @@ static int get_value(config_fn_t fn, char *name, unsigned int len) c = get_next_char(); if (c == EOF) break; - if (!isalnum(c)) + if (!iskeychar(c)) break; name[len++] = tolower(c); if (len >= MAXNAME) @@ -181,7 +186,7 @@ static int get_base_var(char *name) return baselen; if (isspace(c)) return get_extended_base_var(name, baselen, c); - if (!isalnum(c) && c != '.') + if (!iskeychar(c) && c != '.') return -1; if (baselen > MAXNAME / 2) return -1; @@ -350,11 +355,11 @@ int git_config(config_fn_t fn) home = getenv("HOME"); filename = getenv("GIT_CONFIG_LOCAL"); if (!filename) - filename = repo_config = strdup(git_path("config")); + filename = repo_config = xstrdup(git_path("config")); } if (home) { - char *user_config = strdup(mkpath("%s/.gitconfig", home)); + char *user_config = xstrdup(mkpath("%s/.gitconfig", home)); if (!access(user_config, R_OK)) ret = git_config_from_file(fn, user_config); free(user_config); @@ -545,8 +550,8 @@ int git_config_set_multivar(const char* key, const char* value, if (!config_filename) config_filename = git_path("config"); } - config_filename = strdup(config_filename); - lock_file = strdup(mkpath("%s.lock", config_filename)); + config_filename = xstrdup(config_filename); + lock_file = xstrdup(mkpath("%s.lock", config_filename)); /* * Since "key" actually contains the section name and the real @@ -565,7 +570,7 @@ int git_config_set_multivar(const char* key, const char* value, /* * Validate the key and while at it, lower case it for matching. */ - store.key = (char*)malloc(strlen(key)+1); + store.key = xmalloc(strlen(key) + 1); dot = 0; for (i = 0; key[i]; i++) { unsigned char c = key[i]; @@ -573,7 +578,7 @@ int git_config_set_multivar(const char* key, const char* value, dot = 1; /* Leave the extended basename untouched.. */ if (!dot || i > store.baselen) { - if (!isalnum(c) || (i == store.baselen+1 && !isalpha(c))) { + if (!iskeychar(c) || (i == store.baselen+1 && !isalpha(c))) { fprintf(stderr, "invalid key: %s\n", key); free(store.key); ret = 1; @@ -633,7 +638,7 @@ int git_config_set_multivar(const char* key, const char* value, } else store.do_not_match = 0; - store.value_regex = (regex_t*)malloc(sizeof(regex_t)); + store.value_regex = (regex_t*)xmalloc(sizeof(regex_t)); if (regcomp(store.value_regex, value_regex, REG_EXTENDED)) { fprintf(stderr, "Invalid pattern: %s\n",