From dfc61e7c243553da0d39bc4c837e1059e23f6965 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Wed, 25 Apr 2018 13:36:26 -0700 Subject: [PATCH] initialize local variable for UBSAN in PosixEnv function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: It seems clear to me that the variable is initialized before line 492, but it wasn't clear to UBSAN. The failure was: ``` In file included from ./env/io_posix.h:14:0, from env/env_posix.cc:44: ./include/rocksdb/env.h: In member function ‘virtual rocksdb::Status rocksdb::{anonymous}::PosixEnv::NewMemoryMappedFileBuffer(const string&, std::unique_ptr*)’: ./include/rocksdb/env.h:822:36: error: ‘base’ may be used uninitialized in this function [-Werror=maybe-uninitialized] : base(_base), length(_length) {} ^ env/env_posix.cc:482:11: note: ‘base’ was declared here void* base; ``` We can just initialize to nullptr to keep UBSAN happy. Closes https://github.com/facebook/rocksdb/pull/3770 Differential Revision: D7756287 Pulled By: ajkr fbshipit-source-id: 0f2efb9594e2d3a30706a4ca7e1d4a6328031bf2 --- env/env_posix.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/env/env_posix.cc b/env/env_posix.cc index a9895ec78..038d7c44a 100644 --- a/env/env_posix.cc +++ b/env/env_posix.cc @@ -479,7 +479,7 @@ class PosixEnv : public Env { if (status.ok()) { status = GetFileSize(fname, &size); } - void* base; + void* base = nullptr; if (status.ok()) { base = mmap(nullptr, static_cast(size), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);