mirror of https://github.com/facebook/rocksdb.git
Fix up backupable_db stack corruption.
Summary: Fix up OACR(Lint) warnings. Closes https://github.com/facebook/rocksdb/pull/3674 Differential Revision: D7563869 Pulled By: ajkr fbshipit-source-id: 8c1e5045c8a6a2d85b2933fdbc60fde93bf0c9de
This commit is contained in:
parent
d2bcd7611f
commit
5ec382b918
|
@ -3410,10 +3410,6 @@ inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
|
|||
|
||||
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */)
|
||||
|
||||
inline const char* StrNCpy(char* dest, const char* src, size_t n) {
|
||||
return strncpy(dest, src, n);
|
||||
}
|
||||
|
||||
// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
|
||||
// StrError() aren't needed on Windows CE at this time and thus not
|
||||
// defined there.
|
||||
|
|
|
@ -15,9 +15,17 @@
|
|||
namespace rocksdb {
|
||||
|
||||
const char* Status::CopyState(const char* state) {
|
||||
const size_t cch =
|
||||
std::strlen(state) + 1; // +1 for the null terminator
|
||||
char* const result =
|
||||
new char[std::strlen(state) + 1]; // +1 for the null terminator
|
||||
std::strcpy(result, state);
|
||||
new char[cch];
|
||||
#ifdef OS_WIN
|
||||
errno_t ret;
|
||||
ret = strncpy_s(result, cch, state, cch - 1);
|
||||
assert(ret == 0);
|
||||
#else
|
||||
std::strncpy(result, state, cch - 1);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1770,7 +1770,8 @@ Status BackupEngineImpl::BackupMeta::StoreToFile(bool sync) {
|
|||
}
|
||||
|
||||
char writelen_temp[19];
|
||||
if (len + sprintf(writelen_temp, "%" ROCKSDB_PRIszt "\n", files_.size()) >= buf_size) {
|
||||
if (len + snprintf(writelen_temp, sizeof(writelen_temp),
|
||||
"%" ROCKSDB_PRIszt "\n", files_.size()) >= buf_size) {
|
||||
backup_meta_file->Append(Slice(buf.get(), len));
|
||||
buf.reset();
|
||||
unique_ptr<char[]> new_reset_buf(new char[max_backup_meta_file_size_]);
|
||||
|
@ -1785,7 +1786,8 @@ Status BackupEngineImpl::BackupMeta::StoreToFile(bool sync) {
|
|||
for (const auto& file : files_) {
|
||||
// use crc32 for now, switch to something else if needed
|
||||
|
||||
size_t newlen = len + file->filename.length() + sprintf(writelen_temp, " crc32 %u\n", file->checksum_value);
|
||||
size_t newlen = len + file->filename.length() + snprintf(writelen_temp,
|
||||
sizeof(writelen_temp), " crc32 %u\n", file->checksum_value);
|
||||
const char *const_write = writelen_temp;
|
||||
if (newlen >= buf_size) {
|
||||
backup_meta_file->Append(Slice(buf.get(), len));
|
||||
|
|
Loading…
Reference in New Issue