Commit f4b473fa842a84147d8036a27bac5c026c44dad4

Edward Thomson 2020-12-20T21:25:22

Merge pull request #5746 from libgit2/ethomson/configmapcache repository: use intptr_t's in the config map cache

diff --git a/src/config_cache.c b/src/config_cache.c
index 2f0455a..37617af 100644
--- a/src/config_cache.c
+++ b/src/config_cache.c
@@ -111,18 +111,21 @@ int git_config__configmap_lookup(int *out, git_config *config, git_configmap_ite
 
 int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item)
 {
-	*out = (int)(intptr_t)git_atomic_load(repo->configmap_cache[(int)item]);
+	intptr_t value = (intptr_t)git_atomic_load(repo->configmap_cache[(int)item]);
 
-	if (*out == GIT_CONFIGMAP_NOT_CACHED) {
-		int error;
-		int oldval = GIT_CONFIGMAP_NOT_CACHED;
+	*out = (int)value;
+
+	if (value == GIT_CONFIGMAP_NOT_CACHED) {
 		git_config *config;
+		intptr_t oldval = value;
+		int error;
 
 		if ((error = git_repository_config__weakptr(&config, repo)) < 0 ||
 			(error = git_config__configmap_lookup(out, config, item)) < 0)
 			return error;
 
-		git_atomic_compare_and_swap(&repo->configmap_cache[(int)item], &oldval, out);
+		value = *out;
+		git_atomic_compare_and_swap(&repo->configmap_cache[(int)item], (void *)oldval, (void *)value);
 	}
 
 	return 0;
diff --git a/src/repository.h b/src/repository.h
index 4b1222e..c0a2824 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -154,7 +154,7 @@ struct git_repository {
 
 	git_atomic32 attr_session_key;
 
-	git_configmap_value configmap_cache[GIT_CONFIGMAP_CACHE_MAX];
+	intptr_t configmap_cache[GIT_CONFIGMAP_CACHE_MAX];
 	git_strmap *submodule_cache;
 };