threads / patch / 7779

patchFix a typo in crlf conversion code

Subject: [PATCH] Fix a typo in crlf conversion code

## tl;dr

2 messages between Apr 22, 2007 and Apr 22, 2007. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Alex Riesen· Apr 22, 2007, 14:12 UTC · lore

Also, noticed by valgrind: the code caused a read out-of-bounds. Some comments updated as well (they still reflected old calling conventions).

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 convert.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
Show changes to convert.c +5 −5
diff --git a/convert.c b/convert.c
index 37239ac..ad106ef 100644
--- a/convert.c
+++ b/convert.c
@@ -115,8 +115,8 @@ static char *crlf_to_git(const char *path, const char *src, unsigned long *sizep
 	}
 
 	/*
-	 * Ok, allocate a new buffer, fill it in, and return true
-	 * to let the caller know that we switched buffers on it.
+	 * Ok, allocate a new buffer, fill it in, and return it
+	 * to let the caller know that we switched buffers.
 	 */
 	nsize = size - stats.crlf;
 	buffer = xmalloc(nsize);
@@ -137,7 +137,7 @@ static char *crlf_to_git(const char *path, const char *src, unsigned long *sizep
 	} else {
 		do {
 			unsigned char c = *src++;
-			if (! (c == '\r' && (1 < size && *buffer == '\n')))
+			if (! (c == '\r' && (1 < size && *src == '\n')))
 				*dst++ = c;
 		} while (--size);
 	}
@@ -180,8 +180,8 @@ static char *crlf_to_worktree(const char *path, const char *src, unsigned long *
 	}
 
 	/*
-	 * Ok, allocate a new buffer, fill it in, and return true
-	 * to let the caller know that we switched buffers on it.
+	 * Ok, allocate a new buffer, fill it in, and return it
+	 * to let the caller know that we switched buffers.
 	 */
 	nsize = size + stats.lf - stats.crlf;
 	buffer = xmalloc(nsize);
-- 
1.5.1.1.946.gdb75a
Alex Riesen· Apr 22, 2007, 22:52 UTC · re: Alex Riesen · lore

Re: [PATCH] Fix crash in t0020 (crlf conversion)

Alex Riesen, Sun, Apr 22, 2007 16:11:54 +0200:
> Reallocated wrong size.
> Noticed on Ubuntu 7.04 probably because it has some malloc diagnostics in libc:
> "git-read-tree --reset -u HEAD" aborted in the test. Valgrind sped up the
> debugging greatly: took me 10 minutes.
Alex Riesen, Sun, Apr 22, 2007 16:12:22 +0200:
> Also, noticed by valgrind: the code caused a read out-of-bounds.
> Some comments updated as well (they still reflected old calling
> conventions).

Actually, it is all the other way around. The _second_ patch (buffer->src in convert.c, the read out-of-bounds caused overwrite of malloc control structures because of incorrect dst update condition) is for the crash, the first is unrelated, but noticed by valgrind in the same test.

I messed up the commit descriptions completely (Martins mail made me look at the patches again). Sorry

← back to recent threads