git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Rewritten fsck.c:fsck_commit() through using starts_with() instead of memcmp()

From
Bblacksimit <cengoguzhanunlu@gmail.com>
Date
Mar 20, 2014, 05:48 UTC
Message-ID
<1395294508-18301-1-git-send-email-cengoguzhanunlu@gmail.com>
Hi, I've done a microproject, number 15, "Rewrite fsck.c:fsck_commit() to use starts_with() and/or skip_prefix()." I used only starts_with().
memcmp() returns 0 when both are equal, therefore when replacing with starts_with() , I used "!" or deleted where appropriate.
I plan to apply for the GSoC 2014. I expect your feedbacks!
Signed-off-by: Oguzhan Unlu <cengoguzhanunlu@gmail.com>
---
 fsck.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fsck.c b/fsck.c
index 64bf279..d43be98 100644
--- a/fsck.c
+++ b/fsck.c
@@ -290,12 +290,12 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
 	int parents = 0;
 	int err;
 
-	if (memcmp(buffer, "tree ", 5))
+	if (!starts_with(buffer, "tree "))
 		return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'tree' line");
 	if (get_sha1_hex(buffer+5, tree_sha1) || buffer[45] != '\n')
 		return error_func(&commit->object, FSCK_ERROR, "invalid 'tree' line format - bad sha1");
 	buffer += 46;
-	while (!memcmp(buffer, "parent ", 7)) {
+	while (starts_with(buffer, "parent ")) {
 		if (get_sha1_hex(buffer+7, sha1) || buffer[47] != '\n')
 			return error_func(&commit->object, FSCK_ERROR, "invalid 'parent' line format - bad sha1");
 		buffer += 48;
@@ -322,13 +322,13 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
 		if (p || parents)
 			return error_func(&commit->object, FSCK_ERROR, "parent objects missing");
 	}
-	if (memcmp(buffer, "author ", 7))
+	if (!starts_with(buffer, "author "))
 		return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'author' line");
 	buffer += 7;
 	err = fsck_ident(&buffer, &commit->object, error_func);
 	if (err)
 		return err;
-	if (memcmp(buffer, "committer ", strlen("committer ")))
+	if (!starts_with(buffer, "committer "))
 		return error_func(&commit->object, FSCK_ERROR, "invalid format - expected 'committer' line");
 	buffer += strlen("committer ");
 	err = fsck_ident(&buffer, &commit->object, error_func);
-- 
1.9.1.286.g5172cb3
Next: Eric Sunshine
Message 1 of 2 in “Rewritten fsck.c:fsck_commit() through using starts_with() instead of memcmp()”
  1. Rewritten fsck.c:fsck_commit() through using starts_with() instead of memcmp()blacksimit, Mar 20, 2014
  2. Eric SunshineMar 21, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.