sha1_file_name is non-reentrant because of its use of a static buffer. Split it into just the buffer writing (which can be called even from threads as long as the buffer is stack'd) and a small wrapper that uses the static buffer as before. Signed-off-by: Thomas Rast <trast@xxxxxxxxxxxxxxx> --- sha1_file.c | 29 +++++++++++++++++++---------- 1 files changed, 19 insertions(+), 10 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index c3595b3..18648c3 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -153,18 +153,11 @@ static void fill_sha1_path(char *pathbuf, const unsigned char *sha1) } /* - * NOTE! This returns a statically allocated buffer, so you have to be - * careful about using it. Do an "xstrdup()" if you need to save the - * filename. - * - * Also note that this returns the location for creating. Reading - * SHA1 file can happen from any alternate directory listed in the - * DB_ENVIRONMENT environment variable if it is not found in - * the primary object database. + * Similar to sha1_file_name but you provide a buffer of size at least + * PATH_MAX. */ -char *sha1_file_name(const unsigned char *sha1) +void sha1_file_name_buf(char *buf, const unsigned char *sha1) { - static char buf[PATH_MAX]; const char *objdir; int len; @@ -179,6 +172,22 @@ char *sha1_file_name(const unsigned char *sha1) buf[len+3] = '/'; buf[len+42] = '\0'; fill_sha1_path(buf + len + 1, sha1); +} + +/* + * NOTE! This returns a statically allocated buffer, so you have to be + * careful about using it. Do an "xstrdup()" if you need to save the + * filename. + * + * Also note that this returns the location for creating. Reading + * SHA1 file can happen from any alternate directory listed in the + * DB_ENVIRONMENT environment variable if it is not found in + * the primary object database. + */ +char *sha1_file_name(const unsigned char *sha1) +{ + static char buf[PATH_MAX]; + sha1_file_name_buf(buf, sha1); return buf; } -- 1.7.8.431.g2abf2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html