Skip to content

Commit

Permalink
chore(reverse_lookup_dictionary): check file format is compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Apr 1, 2021
1 parent 46e3066 commit 0ee64d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/rime/dict/reverse_lookup_dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// 2012-01-05 GONG Chen <[email protected]>
// 2014-07-06 GONG Chen <[email protected]> redesigned binary file format.
//
#include <cfloat>
#include <cstdlib>
#include <sstream>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
Expand All @@ -18,7 +20,8 @@

namespace rime {

const char kReverseFormat[] = "Rime::Reverse/3.0";
const char kReverseFormat[] = "Rime::Reverse/3.1";
const double kReverseFormatCompatible = 3.0;

const char kReverseFormatPrefix[] = "Rime::Reverse/";
const size_t kReverseFormatPrefixLen = sizeof(kReverseFormatPrefix) - 1;
Expand Down Expand Up @@ -52,7 +55,13 @@ bool ReverseDb::Load() {
Close();
return false;
}
//double format = atof(&metadata_->format[kReverseFormatPrefixLen]);
double format = std::atof(&metadata_->format[kReverseFormatPrefixLen]);
if (format - kReverseFormatCompatible < 0.0 - DBL_EPSILON ||
format - kReverseFormatCompatible > 1.0 + DBL_EPSILON) {
LOG(ERROR) << "incompatible reversedb format.";
Close();
return false;
}

key_trie_.reset(new StringTable(metadata_->key_trie.get(),
metadata_->key_trie_size));
Expand Down
2 changes: 1 addition & 1 deletion src/rime/dict/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace rime {

const char kTableFormatLatest[] = "Rime::Table/4.0";
int kTableFormatLowestCompatible = 4.0;
const int kTableFormatLowestCompatible = 4.0;

const char kTableFormatPrefix[] = "Rime::Table/";
const size_t kTableFormatPrefixLen = sizeof(kTableFormatPrefix) - 1;
Expand Down

0 comments on commit 0ee64d4

Please sign in to comment.