Fix stack overflow

Summary:
Sure, let me put 8 bytes in that int32_t.

Brought to you by ASAN!

Test Plan: ttl_test

Reviewers: dhruba, haobo, kailiu, emayanke

Reviewed By: dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D14193
This commit is contained in:
Igor Canadi 2013-11-18 20:56:21 -08:00
parent 07e8078b17
commit ec0acfbca1
2 changed files with 10 additions and 10 deletions

View File

@ -61,8 +61,8 @@ Status UtilityDB::OpenTtlDB(
}
// Gives back the current time
Status DBWithTTL::GetCurrentTime(int32_t& curtime) {
return Env::Default()->GetCurrentTime((int64_t*)&curtime);
Status DBWithTTL::GetCurrentTime(int64_t& curtime) {
return Env::Default()->GetCurrentTime(&curtime);
}
// Appends the current timestamp to the string.
@ -70,12 +70,12 @@ Status DBWithTTL::GetCurrentTime(int32_t& curtime) {
Status DBWithTTL::AppendTS(const Slice& val, std::string& val_with_ts) {
val_with_ts.reserve(kTSLength + val.size());
char ts_string[kTSLength];
int32_t curtime;
int64_t curtime;
Status st = GetCurrentTime(curtime);
if (!st.ok()) {
return st;
}
EncodeFixed32(ts_string, curtime);
EncodeFixed32(ts_string, (int32_t)curtime);
val_with_ts.append(val.data(), val.size());
val_with_ts.append(ts_string, kTSLength);
return st;
@ -102,7 +102,7 @@ bool DBWithTTL::IsStale(const Slice& value, int32_t ttl) {
if (ttl <= 0) { // Data is fresh if TTL is non-positive
return false;
}
int32_t curtime;
int64_t curtime;
if (!GetCurrentTime(curtime).ok()) {
return false; // Treat the data as fresh if could not get current time
}

View File

@ -100,7 +100,7 @@ class DBWithTTL : public StackableDB {
static Status StripTS(std::string* str);
static Status GetCurrentTime(int32_t& curtime);
static Status GetCurrentTime(int64_t& curtime);
static const uint32_t kTSLength = sizeof(int32_t); // size of timestamp
@ -302,14 +302,14 @@ class TtlMergeOperator : public MergeOperator {
}
// Augment the *new_value with the ttl time-stamp
int32_t curtime;
int64_t curtime;
if (!DBWithTTL::GetCurrentTime(curtime).ok()) {
Log(logger, "Error: Could not get current time to be attached internally "
"to the new value.");
return false;
} else {
char ts_string[ts_len];
EncodeFixed32(ts_string, curtime);
EncodeFixed32(ts_string, (int32_t)curtime);
new_value->append(ts_string, ts_len);
return true;
}
@ -337,14 +337,14 @@ class TtlMergeOperator : public MergeOperator {
}
// Augment the *new_value with the ttl time-stamp
int32_t curtime;
int64_t curtime;
if (!DBWithTTL::GetCurrentTime(curtime).ok()) {
Log(logger, "Error: Could not get current time to be attached internally "
"to the new value.");
return false;
} else {
char ts_string[ts_len];
EncodeFixed32(ts_string, curtime);
EncodeFixed32(ts_string, (int32_t)curtime);
new_value->append(ts_string, ts_len);
return true;
}