summaryrefslogtreecommitdiff
path: root/src/libgit2/oid.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2020-12-08 19:28:44 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2023-05-13 14:09:25 +0100
commit4f76ef568d74c63031eb42fc10bf08b5641e5f0b (patch)
tree7b96d7c1bdf5508c40c22d7517e17da1fe779418 /src/libgit2/oid.c
parentce488be46e4cd2aeeb69c39a062fae1ba9a302f6 (diff)
downloadlibgit2-4f76ef568d74c63031eb42fc10bf08b5641e5f0b.tar.gz
oid: don't assume thread local state was initialized
git_oid_tostr_s could fail if thread-local state initialization fails. In that case, it will now return `NULL`. Callers should check for `NULL` and propagate the failure.
Diffstat (limited to 'src/libgit2/oid.c')
-rw-r--r--src/libgit2/oid.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libgit2/oid.c b/src/libgit2/oid.c
index 6cc21641d..ab758fff4 100644
--- a/src/libgit2/oid.c
+++ b/src/libgit2/oid.c
@@ -155,7 +155,13 @@ int git_oid_pathfmt(char *str, const git_oid *oid)
char *git_oid_tostr_s(const git_oid *oid)
{
- char *str = GIT_THREADSTATE->oid_fmt;
+ git_threadstate *threadstate = GIT_THREADSTATE;
+ char *str;
+
+ if (!threadstate)
+ return NULL;
+
+ str = threadstate->oid_fmt;
git_oid_nfmt(str, git_oid_hexsize(git_oid_type(oid)) + 1, oid);
return str;
}