Skip to contentSkip to conversation

Fix gitmkdtemp: correct test for mktemp() return value

PATCH In review Filippo Negroni 3 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix gitmkdtemp: correct test for mktemp() return value

Quoted 1 line

From 5e3b362cdd86150de901312c01beac9596b7e2ba Mon Sep 17 00:00:00 2001

From: Filippo Negroni <[email protected]>
Date: Thu, 25 Feb 2010 09:39:56 +0000
Subject: [PATCH] Fix gitmkdtemp: correct test for mktemp() return value

In gitmkdtemp, the return value of mktemp is not tested correctly.
mktemp() always returns its 'template' argument, even upon failre.
Upon failure, mktemp sets template to be an empty string: its first character is '\0'.
This patch ensures the return value of mktemp is correctly tested by dereferencing the pointer returned by it.

---
 compat/mkdtemp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
compat/mkdtemp.c +1 -1
index 34d4b49..1136119 100644
@@ -2,7 +2,7 @@
 
 char *gitmkdtemp(char *template)
 {
-       if (!mktemp(template) || mkdir(template, 0700))
+       if (!*mktemp(template) || mkdir(template, 0700))
                return NULL;
        return template;
 }
Signature · 1 line
1.6.4
#1 lore raw
Quoted 5 lines · Filippo Negroni

From 5e3b362cdd86150de901312c01beac9596b7e2ba Mon Sep 17 00:00:00 2001
From: Filippo Negroni <[email protected]>
Date: Thu, 25 Feb 2010 09:39:56 +0000
Subject: [PATCH] Fix gitmkdtemp: correct test for mktemp() return value

Quoted 7 lines

In gitmkdtemp, the return value of mktemp is not tested correctly.
mktemp() always returns its 'template' argument, even upon failre.
Upon failure, mktemp sets template to be an empty string: its first character is '\0'.
This patch ensures the return value of mktemp is correctly tested by dereferencing the pointer returned by it.

---

Thanks.

Next time please do not quote the mbox header lines (i.e. start your body with "In gitmkdtemp, the return value ...".

#2 lore raw
Quoted 2 lines · Junio C Hamano

Next time please do not quote the mbox header lines (i.e. start your body with "In gitmkdtemp, the return value ...".

... or just use "git send-email", which does the trick for you.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/