]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fix retrieval of object file when destination is /dev/null
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 3 Jan 2021 12:39:57 +0000 (13:39 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 3 Jan 2021 13:43:46 +0000 (14:43 +0100)
ResultRetriever::on_entry_data assumes that a destination file has been
opened if the entry type is not stderr_output, but that’s incorrect
since on_entry_start doesn’t open a destination file if it’s /dev/null.
An assertion is triggered:

    ccache: ResultRetriever.cpp:129: virtual void
    ResultRetriever::on_entry_data(const uint8_t *, size_t): failed
    assertion: (m_dest_file_type == FileType::stderr_output &&
    !m_dest_fd) || (m_dest_file_type != FileType::stderr_output &&
    m_dest_fd)

Fix this by letting on_entry_data handle the “destination file not
opened” case and correcting the assert.

Fixes #752.

src/ResultRetriever.cpp
test/suites/base.bash

index 1e45dbb4f9616603b85ecf6e8e5c876dbe8e3ef7..957bbee4929424b81288e70857b2b19157760a9b 100644 (file)
@@ -128,13 +128,12 @@ ResultRetriever::on_entry_start(uint32_t entry_number,
 void
 ResultRetriever::on_entry_data(const uint8_t* data, size_t size)
 {
-  ASSERT((m_dest_file_type == FileType::stderr_output && !m_dest_fd)
-         || (m_dest_file_type != FileType::stderr_output && m_dest_fd));
+  ASSERT(!(m_dest_file_type == FileType::stderr_output && m_dest_fd));
 
   if (m_dest_file_type == FileType::stderr_output
       || (m_dest_file_type == FileType::dependency && !m_dest_path.empty())) {
     m_dest_data.append(reinterpret_cast<const char*>(data), size);
-  } else {
+  } else if (m_dest_fd) {
     try {
       Util::write_fd(*m_dest_fd, data, size);
     } catch (Error& e) {
index 30c1c41f41346c4c07c2c01f36e7a68cc7fe10a9..2131ac92a8d697adf6c7c26ba0119864579ccb98 100644 (file)
@@ -1085,6 +1085,17 @@ EOF
     CCACHE_PREFIX=`pwd`/empty-object-prefix $CCACHE_COMPILE -c test_empty_obj.c
     expect_stat 'compiler produced empty output' 1
 
+    # -------------------------------------------------------------------------
+    TEST "Output to /dev/null"
+
+    $CCACHE_COMPILE -c test1.c
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+
+    $CCACHE_COMPILE -c test1.c -o /dev/null
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 1
+
     # -------------------------------------------------------------------------
     TEST "Caching stderr"