]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fix caching of empty source files in direct mode
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 4 Mar 2010 19:30:27 +0000 (20:30 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 4 Mar 2010 19:30:27 +0000 (20:30 +0100)
comments.c
test.sh

index 117395447c8f213ce7bcc91f953d6671f868e168..771b38b88100ba7292aa1064256c8860a059aaff 100644 (file)
@@ -128,6 +128,10 @@ int hash_file_ignoring_comments(struct mdfour *hash, const char *path)
                close(fd);
                return 0;
        }
+       if (st.st_size == 0) {
+               close(fd);
+               return 1;
+       }
        data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
        close(fd);
        if (data == (void *)-1) {
diff --git a/test.sh b/test.sh
index eda5443be76936e53d08be701256e0e3b7d5331c..cded5cc3d841675df9212fd8de832c498b41184b 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -717,6 +717,20 @@ EOF
     checkstat 'cache hit (preprocessed)' 0
     checkstat 'cache miss' 2
 
+    ##################################################################
+    # Check that it's possible to compile and cache an empty source code file.
+    testname="empty source file"
+    $CCACHE -Cz >/dev/null
+    cp /dev/null empty.c
+    $CCACHE_COMPILE -c empty.c
+    checkstat 'cache hit (direct)' 0
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 1
+    $CCACHE_COMPILE -c empty.c
+    checkstat 'cache hit (direct)' 1
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 1
+
     ##################################################################
     # Reset things.
     CCACHE_NODIRECT=1