Commit 6de9b2ee by Vicent Marti

util: It's called `memzero`

parent eb58e2d0
...@@ -107,7 +107,7 @@ void git_cache_free(git_cache *cache) ...@@ -107,7 +107,7 @@ void git_cache_free(git_cache *cache)
git_cache_clear(cache); git_cache_clear(cache);
git_oidmap_free(cache->map); git_oidmap_free(cache->map);
git_mutex_free(&cache->lock); git_mutex_free(&cache->lock);
git__memset(cache, 0, sizeof(*cache)); git__memzero(cache, sizeof(*cache));
} }
/* Called with lock */ /* Called with lock */
......
...@@ -47,7 +47,7 @@ static void config_free(git_config *cfg) ...@@ -47,7 +47,7 @@ static void config_free(git_config *cfg)
git_vector_free(&cfg->files); git_vector_free(&cfg->files);
git__memset(cfg, 0, sizeof(*cfg)); git__memzero(cfg, sizeof(*cfg));
git__free(cfg); git__free(cfg);
} }
......
...@@ -466,7 +466,7 @@ static void diff_list_free(git_diff_list *diff) ...@@ -466,7 +466,7 @@ static void diff_list_free(git_diff_list *diff)
git_pathspec_free(&diff->pathspec); git_pathspec_free(&diff->pathspec);
git_pool_clear(&diff->pool); git_pool_clear(&diff->pool);
git__memset(diff, 0, sizeof(*diff)); git__memzero(diff, sizeof(*diff));
git__free(diff); git__free(diff);
} }
......
...@@ -349,7 +349,7 @@ static void index_free(git_index *index) ...@@ -349,7 +349,7 @@ static void index_free(git_index *index)
git__free(index->index_file_path); git__free(index->index_file_path);
git__memset(index, 0, sizeof(*index)); git__memzero(index, sizeof(*index));
git__free(index); git__free(index);
} }
......
...@@ -590,7 +590,7 @@ static void odb_free(git_odb *db) ...@@ -590,7 +590,7 @@ static void odb_free(git_odb *db)
git_vector_free(&db->backends); git_vector_free(&db->backends);
git_cache_free(&db->own_cache); git_cache_free(&db->own_cache);
git__memset(db, 0, sizeof(*db)); git__memzero(db, sizeof(*db));
git__free(db); git__free(db);
} }
......
...@@ -89,7 +89,7 @@ int git_refdb_compress(git_refdb *db) ...@@ -89,7 +89,7 @@ int git_refdb_compress(git_refdb *db)
void git_refdb__free(git_refdb *db) void git_refdb__free(git_refdb *db)
{ {
refdb_free_backend(db); refdb_free_backend(db);
git__memset(db, 0, sizeof(*db)); git__memzero(db, sizeof(*db));
git__free(db); git__free(db);
} }
......
...@@ -119,7 +119,7 @@ void git_repository_free(git_repository *repo) ...@@ -119,7 +119,7 @@ void git_repository_free(git_repository *repo)
git__free(repo->workdir); git__free(repo->workdir);
git__free(repo->namespace); git__free(repo->namespace);
git__memset(repo, 0, sizeof(*repo)); git__memzero(repo, sizeof(*repo));
git__free(repo); git__free(repo);
} }
......
...@@ -723,12 +723,11 @@ void git__insertsort_r( ...@@ -723,12 +723,11 @@ void git__insertsort_r(
git__free(swapel); git__free(swapel);
} }
void git__memset(void *data, int c, size_t size) void git__memzero(volatile void *data, size_t size)
{ {
volatile uint8_t *scan = data; volatile uint8_t *scan = data;
uint8_t *end = scan + size; uint8_t *end = scan + size;
uint8_t val = (uint8_t)c;
while (scan < end) while (scan < end)
*scan++ = val; *scan++ = 0x0;
} }
...@@ -322,9 +322,9 @@ extern int git__date_parse(git_time_t *out, const char *date); ...@@ -322,9 +322,9 @@ extern int git__date_parse(git_time_t *out, const char *date);
extern size_t git__unescape(char *str); extern size_t git__unescape(char *str);
/* /*
* Memset that will not be optimized away by the compiler. * Safely zero-out memory, making sure that the compiler
* You usually should just use regular `memset()`. * doesn't optimize away the operation.
*/ */
extern void git__memset(void *data, int c, size_t size); extern void git__memzero(volatile void *data, size_t size);
#endif /* INCLUDE_util_h__ */ #endif /* INCLUDE_util_h__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment