summaryrefslogtreecommitdiff
path: root/hash.h
diff options
context:
space:
mode:
authorLibravatar Matheus Tavares <matheus.bernardino@usp.br>2021-05-17 16:49:03 -0300
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-05-18 05:38:54 +0900
commit3d20ed27b8bdac5c82f4f78af802f9afa499f651 (patch)
tree4ac43f95e03a611d9e87630d9616d27cec0eefff /hash.h
parentGit 2.32-rc0 (diff)
downloadtgif-3d20ed27b8bdac5c82f4f78af802f9afa499f651.tar.xz
parallel-checkout: send the new object_id algo field to the workers
An object_id storing a SHA-1 name has some unused bytes at the end of the hash array. Since these bytes are not used, they are usually not initialized to any value either. However, at parallel_checkout.c:send_one_item() the object_id of a cache entry is copied into a buffer which is later sent to a checkout worker through a pipe write(). This makes Valgrind complain about passing uninitialized bytes to a syscall. The worker won't use these uninitialized bytes either, but the warning could confuse someone trying to debug this code; So instead of using oidcpy(), send_one_item() uses hashcpy() to only copy the used/initialized bytes of the object_id, and leave the remaining part with zeros. However, since cf0983213c ("hash: add an algo member to struct object_id", 2021-04-26), using hashcpy() is no longer sufficient here as it won't copy the new algo field from the object_id. Let's add and use a new function which meets both our requirements of copying all the important object_id data while still avoiding the uninitialized bytes, by padding the end of the hash array in the destination object_id. With this change, we also no longer need the destination buffer from send_one_item() to be initialized with zeros, so let's switch from xcalloc() to xmalloc() to make this clear. Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hash.h')
-rw-r--r--hash.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/hash.h b/hash.h
index 2986f991c6..9c6df4d952 100644
--- a/hash.h
+++ b/hash.h
@@ -263,6 +263,22 @@ static inline void oidcpy(struct object_id *dst, const struct object_id *src)
dst->algo = src->algo;
}
+/* Like oidcpy() but zero-pads the unused bytes in dst's hash array. */
+static inline void oidcpy_with_padding(struct object_id *dst,
+ struct object_id *src)
+{
+ size_t hashsz;
+
+ if (!src->algo)
+ hashsz = the_hash_algo->rawsz;
+ else
+ hashsz = hash_algos[src->algo].rawsz;
+
+ memcpy(dst->hash, src->hash, hashsz);
+ memset(dst->hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
+ dst->algo = src->algo;
+}
+
static inline struct object_id *oiddup(const struct object_id *src)
{
struct object_id *dst = xmalloc(sizeof(struct object_id));