diff options
author | Linus Torvalds <torvalds@osdl.org> | 2006-05-03 17:21:08 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-05-03 22:06:45 -0700 |
commit | dcb3450fd8785d76dd3d25aa49be66190aa5e7f3 (patch) | |
tree | d67f23c99110c10edb5383bf5d98dc0da16edd39 /sha1_file.c | |
parent | 935e714204fe167aa6172a733e7131ee5b4577f4 (diff) | |
download | git-dcb3450fd8785d76dd3d25aa49be66190aa5e7f3.tar.gz |
sha1_to_hex() usage cleanup
Somebody on the #git channel complained that the sha1_to_hex() thing uses
a static buffer which caused an error message to show the same hex output
twice instead of showing two different ones.
That's pretty easily rectified by making it uses a simple LRU of a few
buffers, which also allows some other users (that were aware of the buffer
re-use) to be written in a more straightforward manner.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/sha1_file.c b/sha1_file.c index f2d33afb27..5464828259 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -108,9 +108,10 @@ int safe_create_leading_directories(char *path) char * sha1_to_hex(const unsigned char *sha1) { - static char buffer[50]; + static int bufno; + static char hexbuffer[4][50]; static const char hex[] = "0123456789abcdef"; - char *buf = buffer; + char *buffer = hexbuffer[3 & ++bufno], *buf = buffer; int i; for (i = 0; i < 20; i++) { |