From 9ef7223058a44990dc4650ecb1209c97ceb636b3 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Tue, 30 May 2017 10:30:40 -0700 Subject: notes: make get_note return pointer to struct object_id Make get_note return a pointer to a const struct object_id. Add a defensive check to ensure we don't accidentally dereference a NULL pointer. Signed-off-by: brian m. carlson Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- notes-cache.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'notes-cache.c') diff --git a/notes-cache.c b/notes-cache.c index 2843e98576..6e84a748f0 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -69,15 +69,15 @@ int notes_cache_write(struct notes_cache *c) char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid, size_t *outsize) { - const unsigned char *value_sha1; + const struct object_id *value_oid; enum object_type type; char *value; unsigned long size; - value_sha1 = get_note(&c->tree, key_oid->hash); - if (!value_sha1) + value_oid = get_note(&c->tree, key_oid->hash); + if (!value_oid) return NULL; - value = read_sha1_file(value_sha1, &type, &size); + value = read_sha1_file(value_oid->hash, &type, &size); *outsize = size; return value; -- cgit v1.2.1 From 5ee8a954e0191be2a144afdda6e37ef776730246 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Tue, 30 May 2017 10:30:43 -0700 Subject: notes: convert some accessor functions to struct object_id Convert add_note, get_note, and copy_note to take struct object_id. Signed-off-by: brian m. carlson Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- notes-cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'notes-cache.c') diff --git a/notes-cache.c b/notes-cache.c index 6e84a748f0..29b4cede5f 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -74,7 +74,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid, char *value; unsigned long size; - value_oid = get_note(&c->tree, key_oid->hash); + value_oid = get_note(&c->tree, key_oid); if (!value_oid) return NULL; value = read_sha1_file(value_oid->hash, &type, &size); @@ -90,5 +90,5 @@ int notes_cache_put(struct notes_cache *c, struct object_id *key_oid, if (write_sha1_file(data, size, "blob", value_oid.hash) < 0) return -1; - return add_note(&c->tree, key_oid->hash, value_oid.hash, NULL); + return add_note(&c->tree, key_oid, &value_oid, NULL); } -- cgit v1.2.1