summaryrefslogtreecommitdiff
path: root/notes.c
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2017-05-30 10:30:40 -0700
committerJunio C Hamano <gitster@pobox.com>2017-06-02 09:36:06 +0900
commit9ef7223058a44990dc4650ecb1209c97ceb636b3 (patch)
treee3aa8240bac2be6a2bf5ad158023ec31a67d3457 /notes.c
parent490bc83a01acfefa11e98f8852b1f4a9dd962331 (diff)
downloadgit-9ef7223058a44990dc4650ecb1209c97ceb636b3.tar.gz
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 <sandals@crustytoothpaste.net> Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'notes.c')
-rw-r--r--notes.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/notes.c b/notes.c
index e881c10ee9..fe4db2c1ec 100644
--- a/notes.c
+++ b/notes.c
@@ -1119,7 +1119,7 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
return 0;
}
-const unsigned char *get_note(struct notes_tree *t,
+const struct object_id *get_note(struct notes_tree *t,
const unsigned char *object_sha1)
{
struct leaf_node *found;
@@ -1128,7 +1128,7 @@ const unsigned char *get_note(struct notes_tree *t,
t = &default_notes_tree;
assert(t->initialized);
found = note_tree_find(t, t->root, 0, object_sha1);
- return found ? found->val_oid.hash : NULL;
+ return found ? &found->val_oid : NULL;
}
int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
@@ -1219,7 +1219,7 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
struct strbuf *sb, const char *output_encoding, int raw)
{
static const char utf8[] = "utf-8";
- const unsigned char *sha1;
+ const struct object_id *oid;
char *msg, *msg_p;
unsigned long linelen, msglen;
enum object_type type;
@@ -1229,11 +1229,11 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
if (!t->initialized)
init_notes(t, NULL, NULL, 0);
- sha1 = get_note(t, object_sha1);
- if (!sha1)
+ oid = get_note(t, object_sha1);
+ if (!oid)
return;
- if (!(msg = read_sha1_file(sha1, &type, &msglen)) || type != OBJ_BLOB) {
+ if (!(msg = read_sha1_file(oid->hash, &type, &msglen)) || type != OBJ_BLOB) {
free(msg);
return;
}
@@ -1291,14 +1291,14 @@ int copy_note(struct notes_tree *t,
const unsigned char *from_obj, const unsigned char *to_obj,
int force, combine_notes_fn combine_notes)
{
- const unsigned char *note = get_note(t, from_obj);
- const unsigned char *existing_note = get_note(t, to_obj);
+ const struct object_id *note = get_note(t, from_obj);
+ const struct object_id *existing_note = get_note(t, to_obj);
if (!force && existing_note)
return 1;
if (note)
- return add_note(t, to_obj, note, combine_notes);
+ return add_note(t, to_obj, note->hash, combine_notes);
else if (existing_note)
return add_note(t, to_obj, null_sha1, combine_notes);