summaryrefslogtreecommitdiff
path: root/src/refs.h
diff options
context:
space:
mode:
authorEtienne Samson <samson.etienne@gmail.com>2019-12-08 15:25:52 +0100
committerEtienne Samson <samson.etienne@gmail.com>2019-12-13 12:01:10 +0100
commit97b8491b01e99790a9f643a9571baf65fe168ba8 (patch)
tree20909fe04fa4eca5137c98fd06d80c026b94e896 /src/refs.h
parent39f78b0c03ccaffd5c4aae97897b616634cae3cf (diff)
downloadlibgit2-97b8491b01e99790a9f643a9571baf65fe168ba8.tar.gz
refs: rename git_reference__set_name to git_reference__realloc
As git_reference__name will reallocate storage to account for longer names (it's actually allocator-dependent), it will cause all existing pointers to the old object to become dangling, as they now point to freed memory. Fix the issue by renaming to a more descriptive name, and pass a pointer to the actual reference that can safely be invalidated if the realloc succeeds.
Diffstat (limited to 'src/refs.h')
-rw-r--r--src/refs.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/refs.h b/src/refs.h
index 46df95eba..adc345a12 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -75,7 +75,14 @@ struct git_reference {
char name[GIT_FLEX_ARRAY];
};
-git_reference *git_reference__set_name(git_reference *ref, const char *name);
+/**
+ * Reallocate the reference with a new name
+ *
+ * Note that this is a dangerous operation, as on success, all existing
+ * pointers to the old reference will now be dangling. Only call this on objects
+ * you control, possibly using `git_reference_dup`.
+ */
+git_reference *git_reference__realloc(git_reference **ptr_to_ref, const char *name);
int git_reference__normalize_name(git_buf *buf, const char *name, unsigned int flags);
int git_reference__update_terminal(git_repository *repo, const char *ref_name, const git_oid *oid, const git_signature *sig, const char *log_message);