git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/2] config: Add hashtable for config parsing & retrieval

From
Jeff King <peff@peff.net>
Date
Jun 17, 2014, 05:34 UTC
Message-ID
<20140617053436.GB29957@sigill.intra.peff.net>
In-Reply-To
<1402907232-24629-3-git-send-email-tanayabh@gmail.com>
On Mon, Jun 16, 2014 at 01:27:12AM -0700, Tanay Abhra wrote:
Show 5 quoted lines
> +static int config_cache_callback(const char *key, const char *value, void *unused)
> +{
> +	config_cache_set_value(key, value);
> +	return 0;
> +}

This gets the normalized key, which is good; you should be able to just hash/lookup values without further munging as long as they, too, are normalized (you may want to note that in the documentaiton for config_cache_find_entry and friends).

The value may be a string value, or NULL if it is a true boolean. That value gets passed to...

Show 19 quoted lines
> +static int config_cache_set_value(const char *key, const char *value)
> +{
> +	struct hashmap *config_cache;
> +	struct config_cache_entry *e;
> +
> +	config_cache = get_config_cache();
> +	e = config_cache_find_entry(key);
> +	if (!e) {
> +		e = xmalloc(sizeof(*e));
> +		hashmap_entry_init(e, strhash(key));
> +		e->key = xstrdup(key);
> +		string_list_init_dup(&e->value_list);
> +		string_list_append(&e->value_list, value);
> +		hashmap_add(config_cache, e);
> +	} else {
> +		string_list_append(&e->value_list, value);
> +	}
> +	return 0;
> +}

...this function, which then passes it to string_list_append. Which is going to call xstrdup() on it, which will then segfault.

You need some mechanism to store entries that are NULL. It may be enough to silently convert them into the string "true" inside the cached storage. But there may be callers who treat NULL specially (e.g., a tri-state true/false/auto that treats a bare boolean as "auto"); you'd need to check.

The other alternative is to use something besides string_list that can handle a NULL. You may also need to give some thought to how such NULLs would be handled by git_config_get_string() (since a NULL there also means "not found").

-Peff
Previous: Matthieu MoyNext: Jeff King
Message 10 of 11 in “Git config cache & special querying api utilizing the cache”
  1. 0/2 Git config cache & special querying api utilizing the cacheTanay Abhra, Jun 16, 2014
  2. 1/2 string-list: Add string_list initializer helper functionsTanay Abhra, Jun 16, 2014
  3. Junio C HamanoJun 16, 2014
  4. Tanay AbhraJun 17, 2014
  5. Junio C HamanoJun 17, 2014
  6. 2/2 config: Add hashtable for config parsing & retrievalTanay Abhra, Jun 16, 2014
  7. Matthieu MoyJun 16, 2014
  8. Tanay AbhraJun 16, 2014
  9. Matthieu MoyJun 16, 2014
  10. Jeff KingJun 17, 2014
  11. Jeff KingJun 17, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.