Skip to content

Commit ae6f064

Browse files
peffgitster
authored andcommitted
notes: clean up confusing NULL checks in init_notes()
Coverity complains that we check whether "notes_ref" is NULL, but it was already implied to be non-NULL earlier in the function. And this is true; since b9342b3 (refs: add array of ref namespaces, 2022-08-05), we call xstrdup(notes_ref) unconditionally, which would segfault if it was NULL. But that commit is actually doing the right thing. Even if NULL is passed into the function, we'll use default_notes_ref() as a fallback, which will never return NULL (it tries a few options, but its last resort is a string literal). Ironically, the "!notes_ref" check was added by the same commit that added the fallback: 709f79b (Notes API: init_notes(): Initialize the notes tree from the given notes ref, 2010-02-13). So this check never did anything. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7580f92 commit ae6f064

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

notes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,13 +1019,13 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
10191019
t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node));
10201020
t->first_non_note = NULL;
10211021
t->prev_non_note = NULL;
1022-
t->ref = xstrdup_or_null(notes_ref);
1022+
t->ref = xstrdup(notes_ref);
10231023
t->update_ref = (flags & NOTES_INIT_WRITABLE) ? t->ref : NULL;
10241024
t->combine_notes = combine_notes;
10251025
t->initialized = 1;
10261026
t->dirty = 0;
10271027

1028-
if (flags & NOTES_INIT_EMPTY || !notes_ref ||
1028+
if (flags & NOTES_INIT_EMPTY ||
10291029
repo_get_oid_treeish(the_repository, notes_ref, &object_oid))
10301030
return;
10311031
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))

0 commit comments

Comments
 (0)