Initialize a boolean member variable of a struct.

Summary:
The reason for this initialization is that LLVM UBSAN check will fail due to
uninitialized bool. [StackOverflow post](https://stackoverflow.com/questions/31420154/runtime-error-load-of-value-127-which-is-not-a-valid-value-for-type-bool).

UBSAN log:
> ===== Running external_sst_file_basic_test
[==========] Running 7 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 7 tests from ExternalSSTFileBasicTest
[ RUN      ] ExternalSSTFileBasicTest.Basic
[       OK ] ExternalSSTFileBasicTest.Basic (6 ms)
[ RUN      ] ExternalSSTFileBasicTest.NoCopy
db/external_sst_file_ingestion_job.h:23:8: runtime error: load of value 253, which is not a valid value for type 'bool'

miasantreble  I've tested this locally using the following command.
```
TEST_TMPDIR=/dev/shm/rocksdb COMPILE_WITH_UBSAN=1 OPT=-g make J=1 -j8 ubsan_check
```

ajkr This PR is related to your review comment in [PR](https://github.com/facebook/rocksdb/pull/3713/). It turns out that, with UBSAN enabled, we must provide a default value for boolean member variables.
Closes https://github.com/facebook/rocksdb/pull/3728

Differential Revision: D7642476

Pulled By: riversand963

fbshipit-source-id: 4c09a4b8d271151cb99ae7393db9e4ad9f29762e
This commit is contained in:
Yanqin Jin 2018-04-16 14:18:51 -07:00 committed by Facebook Github Bot
parent af95aecd01
commit 5e48811844

View File

@ -53,8 +53,11 @@ struct IngestedFileInfo {
int picked_level = 0; int picked_level = 0;
// Whether to copy or link the external sst file. copy_file will be set to // Whether to copy or link the external sst file. copy_file will be set to
// false if ingestion_options.move_files is true and underlying FS // false if ingestion_options.move_files is true and underlying FS
// supports link operation. // supports link operation. Need to provide a default value to make the
bool copy_file; // undefined-behavior sanity check of llvm happy. Since
// ingestion_options.move_files is false by default, thus copy_file is true
// by default.
bool copy_file = true;
InternalKey smallest_internal_key() const { InternalKey smallest_internal_key() const {
return InternalKey(smallest_user_key, assigned_seqno, return InternalKey(smallest_user_key, assigned_seqno,