xmkstemp(): avoid showing truncated template more carefully
authorJunio C Hamano <gitster@pobox.com>
Tue, 18 Dec 2012 20:51:35 +0000 (12:51 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Dec 2012 21:02:33 +0000 (13:02 -0800)
Some implementations of xmkstemp() leaves the given in/out buffer
truncated when they return with failure.

6cf6bb3 (Improve error messages when temporary file creation fails,
2010-12-18) attempted to show the real filename we tried to create
(but failed), and if that is not available due to such truncation,
to show the original template that was given by the caller.

But it failed to take into account that the given template could
have "directory/" in front, in which case the truncation point may
not be template[0] but somewhere else.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
wrapper.c
index 68739aaa3b9e9e1a1bbbd43c75c9b5c244fb6c3e..a066e2ee9e2cc90ad77547ee9f2267e255cf7d23 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -229,7 +229,7 @@ int xmkstemp(char *template)
                int saved_errno = errno;
                const char *nonrelative_template;
 
-               if (!template[0])
+               if (strlen(template) != strlen(origtemplate))
                        template = origtemplate;
 
                nonrelative_template = absolute_path(template);