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

[PATCH] Cleanup read_cache_from error handling.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Dec 26, 2006, 04:40 UTC
Message-ID
<20061226044058.GA28359@spearce.org>

When I converted the mmap() call to xmmap() I failed to cleanup the way this routine handles errors and left some crufty code behind. This is a small cleanup, suggested by Johannes.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 This is on top of my sp/mmap topic.
 read-cache.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index ca3efbb..29cf9ab 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -793,16 +793,16 @@ int read_cache_from(const char *path)
 		die("index file open failed (%s)", strerror(errno));
 	}
 
-	cache_mmap = MAP_FAILED;
 	if (!fstat(fd, &st)) {
 		cache_mmap_size = st.st_size;
 		errno = EINVAL;
 		if (cache_mmap_size >= sizeof(struct cache_header) + 20)
 			cache_mmap = xmmap(NULL, cache_mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
-	}
+		else
+			die("index file smaller than expected");
+	} else
+		die("cannot stat the open index (%s)", strerror(errno));
 	close(fd);
-	if (cache_mmap == MAP_FAILED)
-		die("index file mmap failed (%s)", strerror(errno));
 
 	hdr = cache_mmap;
 	if (verify_hdr(hdr, cache_mmap_size) < 0)
-- 
1.4.4.3.gd2e4
Message 1 of 1 in “Cleanup read_cache_from error handling.”
  1. Cleanup read_cache_from error handling.Shawn O. Pearce, Dec 26, 2006

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.