git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH next] log_ref_setup: don't return stack-allocated array
@ 2010-06-10 12:43 Thomas Rast
  2010-06-10 12:54 ` [PATCH next v2] " Thomas Rast
  0 siblings, 1 reply; 11+ messages in thread
From: Thomas Rast @ 2010-06-10 12:43 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Erick Mattos, Ævar Arnfjörð Bjarmason

859c301 (refs: split log_ref_write logic into log_ref_setup,
2010-05-21) refactors the stack allocation of the log_file array into
the new log_ref_setup() function, but passes it back to the caller.

Since the original intent seems to have been to split the work between
log_ref_setup and log_ref_write, make it the caller's responsibility
to allocate the buffer.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Reported-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---

Causes t5516 to fail, but only if I run it under valgrind.  (Ævar
managed to trigger it in other ways apparently.)

 refs.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/refs.c b/refs.c
index 3436649..2a3eeec 100644
--- a/refs.c
+++ b/refs.c
@@ -1262,13 +1262,11 @@ static int copy_msg(char *buf, const char *msg)
 	return cp - buf;
 }
 
-int log_ref_setup(const char *ref_name, char **log_file)
+int log_ref_setup(const char *ref_name, char *logfile, int bufsize)
 {
 	int logfd, oflags = O_APPEND | O_WRONLY;
-	char logfile[PATH_MAX];
 
-	git_snpath(logfile, sizeof(logfile), "logs/%s", ref_name);
-	*log_file = logfile;
+	git_snpath(logfile, bufsize, "logs/%s", ref_name);
 	if (log_all_ref_updates &&
 	    (!prefixcmp(ref_name, "refs/heads/") ||
 	     !prefixcmp(ref_name, "refs/remotes/") ||
@@ -1309,14 +1307,14 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
 	int logfd, result, written, oflags = O_APPEND | O_WRONLY;
 	unsigned maxlen, len;
 	int msglen;
-	char *log_file;
+	char log_file[PATH_MAX];
 	char *logrec;
 	const char *committer;
 
 	if (log_all_ref_updates < 0)
 		log_all_ref_updates = !is_bare_repository();
 
-	result = log_ref_setup(ref_name, &log_file);
+	result = log_ref_setup(ref_name, log_file, sizeof(log_file));
 	if (result)
 		return result;
 
-- 
1.7.1.553.ga798e

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-06-11 18:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-10 12:43 [PATCH next] log_ref_setup: don't return stack-allocated array Thomas Rast
2010-06-10 12:54 ` [PATCH next v2] " Thomas Rast
2010-06-10 16:48   ` Erick Mattos
2010-06-10 17:29     ` Thomas Rast
2010-06-10 23:09       ` Erick Mattos
2010-06-11  5:12         ` Jeff King
2010-06-11 18:54           ` Erick Mattos
     [not found]   ` <AANLkTinI44rPfeXvWr-7jvAVyw5itX_gUsHimwSL74Lv@mail.gmail.com>
2010-06-10 18:09     ` Ævar Arnfjörð Bjarmason
2010-06-10 18:43       ` [PATCH] check_aliased_update: strcpy() instead of strcat() to copy Thomas Rast
2010-06-10 19:00         ` Ævar Arnfjörð Bjarmason
2010-06-10 19:26         ` Jay Soffian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).