summaryrefslogtreecommitdiff
path: root/strbuf.h
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2015-09-24 17:05:45 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-09-25 10:18:18 -0700
commitaf49c6d0918bf04aad89bd885a4eef5767a33d0e (patch)
tree5037171be3cd4be197a9fafdbbcec9b305b96f99 /strbuf.h
parentstrbuf: make strbuf_complete_line more generic (diff)
downloadtgif-af49c6d0918bf04aad89bd885a4eef5767a33d0e.tar.xz
add reentrant variants of sha1_to_hex and find_unique_abbrev
The sha1_to_hex and find_unique_abbrev functions always write into reusable static buffers. There are a few problems with this: - future calls overwrite our result. This is especially annoying with find_unique_abbrev, which does not have a ring of buffers, so you cannot even printf() a result that has two abbreviated sha1s. - if you want to put the result into another buffer, we often strcpy, which looks suspicious when auditing for overflows. This patch introduces sha1_to_hex_r and find_unique_abbrev_r, which write into a user-provided buffer. Of course this is just punting on the overflow-auditing, as the buffer obviously needs to be GIT_SHA1_HEXSZ + 1 bytes. But it is much easier to audit, since that is a well-known size. We retain the non-reentrant forms, which just become thin wrappers around the reentrant ones. This patch also adds a strbuf variant of find_unique_abbrev, which will be handy in later patches. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'strbuf.h')
-rw-r--r--strbuf.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/strbuf.h b/strbuf.h
index 43f27c3a69..0f9c8a72ba 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -475,6 +475,14 @@ static inline struct strbuf **strbuf_split(const struct strbuf *sb,
extern void strbuf_list_free(struct strbuf **);
/**
+ * Add the abbreviation, as generated by find_unique_abbrev, of `sha1` to
+ * the strbuf `sb`.
+ */
+extern void strbuf_add_unique_abbrev(struct strbuf *sb,
+ const unsigned char *sha1,
+ int abbrev_len);
+
+/**
* Launch the user preferred editor to edit a file and fill the buffer
* with the file's contents upon the user completing their editing. The
* third argument can be used to set the environment which the editor is