From 6de9b2ee14a2393fae3ed86c5a5d12712c83b083 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Wed, 12 Jun 2013 21:10:33 +0200 Subject: [PATCH] util: It's called `memzero` --- src/cache.c | 2 +- src/config.c | 2 +- src/diff.c | 2 +- src/index.c | 2 +- src/odb.c | 2 +- src/refdb.c | 2 +- src/repository.c | 2 +- src/util.c | 5 ++--- src/util.h | 6 +++--- 9 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/cache.c b/src/cache.c index 570838e44..36ce66570 100644 --- a/src/cache.c +++ b/src/cache.c @@ -107,7 +107,7 @@ void git_cache_free(git_cache *cache) git_cache_clear(cache); git_oidmap_free(cache->map); git_mutex_free(&cache->lock); - git__memset(cache, 0, sizeof(*cache)); + git__memzero(cache, sizeof(*cache)); } /* Called with lock */ diff --git a/src/config.c b/src/config.c index 006025903..068c40260 100644 --- a/src/config.c +++ b/src/config.c @@ -47,7 +47,7 @@ static void config_free(git_config *cfg) git_vector_free(&cfg->files); - git__memset(cfg, 0, sizeof(*cfg)); + git__memzero(cfg, sizeof(*cfg)); git__free(cfg); } diff --git a/src/diff.c b/src/diff.c index bd2b88167..3bfe149e3 100644 --- a/src/diff.c +++ b/src/diff.c @@ -466,7 +466,7 @@ static void diff_list_free(git_diff_list *diff) git_pathspec_free(&diff->pathspec); git_pool_clear(&diff->pool); - git__memset(diff, 0, sizeof(*diff)); + git__memzero(diff, sizeof(*diff)); git__free(diff); } diff --git a/src/index.c b/src/index.c index d519954c5..4f0c70135 100644 --- a/src/index.c +++ b/src/index.c @@ -349,7 +349,7 @@ static void index_free(git_index *index) git__free(index->index_file_path); - git__memset(index, 0, sizeof(*index)); + git__memzero(index, sizeof(*index)); git__free(index); } diff --git a/src/odb.c b/src/odb.c index 5e27edacd..8e62efd00 100644 --- a/src/odb.c +++ b/src/odb.c @@ -590,7 +590,7 @@ static void odb_free(git_odb *db) git_vector_free(&db->backends); git_cache_free(&db->own_cache); - git__memset(db, 0, sizeof(*db)); + git__memzero(db, sizeof(*db)); git__free(db); } diff --git a/src/refdb.c b/src/refdb.c index 6da409aac..4de7188b2 100644 --- a/src/refdb.c +++ b/src/refdb.c @@ -89,7 +89,7 @@ int git_refdb_compress(git_refdb *db) void git_refdb__free(git_refdb *db) { refdb_free_backend(db); - git__memset(db, 0, sizeof(*db)); + git__memzero(db, sizeof(*db)); git__free(db); } diff --git a/src/repository.c b/src/repository.c index 9cb093dd9..ed9469c59 100644 --- a/src/repository.c +++ b/src/repository.c @@ -119,7 +119,7 @@ void git_repository_free(git_repository *repo) git__free(repo->workdir); git__free(repo->namespace); - git__memset(repo, 0, sizeof(*repo)); + git__memzero(repo, sizeof(*repo)); git__free(repo); } diff --git a/src/util.c b/src/util.c index 248cf4c42..1d084daa8 100644 --- a/src/util.c +++ b/src/util.c @@ -723,12 +723,11 @@ void git__insertsort_r( 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; uint8_t *end = scan + size; - uint8_t val = (uint8_t)c; while (scan < end) - *scan++ = val; + *scan++ = 0x0; } diff --git a/src/util.h b/src/util.h index 9417515a3..0de466677 100644 --- a/src/util.h +++ b/src/util.h @@ -322,9 +322,9 @@ extern int git__date_parse(git_time_t *out, const char *date); extern size_t git__unescape(char *str); /* - * Memset that will not be optimized away by the compiler. - * You usually should just use regular `memset()`. + * Safely zero-out memory, making sure that the compiler + * 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__ */