compat/mkdtemp.c: patch for gitmkdtemp() compatibility implementation

From: Filippo Negroni <hidden>
Date: 2016-06-15 22:48:21

Dear all,

I noticed that the current implementation of mkdtemp() in the compat/ directory does not seem to be correct.

gitmkdtemp() is needed for platforms such as Solaris 9 and 10 which do not implement mkdtemp().

The current implementation (compat/mkdtemp.c):

----
char *gitmkdtemp(char *template)
{
        if (!mktemp(template) || mkdir(template, 0700))
                return NULL;
        return template;
}
----

seems to be testing the return value of mktemp incorrectly.

mktemp() always returns the argument 'template', even on failure.

This is an extract from Solaris's mktemp(2) manual page:

RETURN VALUES
     The mktemp() function will  assign  to  template  the  empty
     string if it  cannot create a unique name.

Upon failure, 'template' is set to an empty string, i.e., it's first character is '\0'.

The fixed implementation should read:

----
char *gitmkdtemp(char *template)
{
        if (!*mktemp(template) || mkdir(template, 0700))
                return NULL;
        return template;
}
----

I.e., simply add the pointer dereference operator when calling mktemp().

I have attached a patch against the most current git repo, branch master.

Please let me know if you need the patch in any other way.

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help