{"thread":{"id":"6113","subject":"[PATCH] Cleanup read_cache_from error handling.","startedAt":"2006-12-26T04:40:58Z","lastAt":"2006-12-26T04:40:58Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"30292","messageId":"20061226044058.GA28359@spearce.org","threadId":"6113","inReplyTo":null,"subject":"[PATCH] Cleanup read_cache_from error handling.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-26T04:40:58Z","receivedAt":"2006-12-26T04:40:58Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"When I converted the mmap() call to xmmap() I failed to cleanup the\nway this routine handles errors and left some crufty code behind.\nThis is a small cleanup, suggested by Johannes.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n This is on top of my sp/mmap topic.\n\n read-cache.c |    8 ++++----\n 1 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex ca3efbb..29cf9ab 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -793,16 +793,16 @@ int read_cache_from(const char *path)\n \t\tdie(\"index file open failed (%s)\", strerror(errno));\n \t}\n \n-\tcache_mmap = MAP_FAILED;\n \tif (!fstat(fd, &st)) {\n \t\tcache_mmap_size = st.st_size;\n \t\terrno = EINVAL;\n \t\tif (cache_mmap_size >= sizeof(struct cache_header) + 20)\n \t\t\tcache_mmap = xmmap(NULL, cache_mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);\n-\t}\n+\t\telse\n+\t\t\tdie(\"index file smaller than expected\");\n+\t} else\n+\t\tdie(\"cannot stat the open index (%s)\", strerror(errno));\n \tclose(fd);\n-\tif (cache_mmap == MAP_FAILED)\n-\t\tdie(\"index file mmap failed (%s)\", strerror(errno));\n \n \thdr = cache_mmap;\n \tif (verify_hdr(hdr, cache_mmap_size) < 0)\n-- \n1.4.4.3.gd2e4\n"}]}