From 8c2b921fdf1335814b5cc093d7bce06d4a65b9ab Mon Sep 17 00:00:00 2001 From: Mike Kolupaev Date: Fri, 9 Dec 2016 10:23:58 -0800 Subject: [PATCH] Fixed a crash in debug build in flush_job.cc Summary: It was doing `&range_del_iters[0]` on an empty vector. Even though the resulting pointer is never dereferenced, it's still bad for two reasons: * the practical reason: it crashes with `std::out_of_range` exception in our debug build, * the "C++ standard lawyer" reason: it's undefined behavior because, in `std::vector` implementation, it probably "dereferences" a null pointer, which is invalid even though it doesn't actually read the pointed memory, just converts a pointer into a reference (and then flush_job.cc converts it back to pointer); nullptr references are undefined behavior. Closes https://github.com/facebook/rocksdb/pull/1612 Differential Revision: D4265625 Pulled By: al13n321 fbshipit-source-id: db26fb9 --- db/flush_job.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/flush_job.cc b/db/flush_job.cc index 80914e06f..33c295a5f 100644 --- a/db/flush_job.cc +++ b/db/flush_job.cc @@ -277,7 +277,8 @@ Status FlushJob::WriteLevel0Table() { NewMergingIterator(&cfd_->internal_comparator(), &memtables[0], static_cast(memtables.size()), &arena)); std::unique_ptr range_del_iter(NewMergingIterator( - &cfd_->internal_comparator(), &range_del_iters[0], + &cfd_->internal_comparator(), + range_del_iters.empty() ? nullptr : &range_del_iters[0], static_cast(range_del_iters.size()))); Log(InfoLogLevel::INFO_LEVEL, db_options_.info_log, "[%s] [JOB %d] Level-0 flush table #%" PRIu64 ": started",