提交 0ab8692b 编写于 作者: A Alexey Milovidov

re2: fixed warnings [#METR-17973].

上级 80284a4a
......@@ -591,7 +591,7 @@ static struct ByteRangeProg {
void Compiler::Add_80_10ffff() {
int inst[arraysize(prog_80_10ffff)] = { 0 }; // does not need to be initialized; silences gcc warning
for (int i = 0; i < arraysize(prog_80_10ffff); i++) {
for (size_t i = 0; i < arraysize(prog_80_10ffff); i++) {
const ByteRangeProg& p = prog_80_10ffff[i];
int next = 0;
if (p.next >= 0)
......@@ -958,7 +958,7 @@ void Compiler::Setup(Regexp::ParseFlags flags, int64 max_mem,
max_mem_ = max_mem;
if (max_mem <= 0) {
max_inst_ = 100000; // more than enough
} else if (max_mem <= sizeof(Prog)) {
} else if (max_mem <= static_cast<int64>(sizeof(Prog))) {
// No room for anything.
max_inst_ = 0;
} else {
......
......@@ -787,7 +787,7 @@ void DFA::ClearCache() {
it != state_cache_.end(); ++it)
v.push_back(*it);
state_cache_.clear();
for (int i = 0; i < v.size(); i++)
for (size_t i = 0; i < v.size(); i++)
delete[] reinterpret_cast<const char*>(v[i]);
}
......@@ -1394,7 +1394,7 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,
// of 10 bytes per state computation, fail so that RE2 can
// fall back to the NFA.
if (FLAGS_re2_dfa_bail_when_slow && resetp != NULL &&
(p - resetp) < 10*state_cache_.size()) {
(p - resetp) < static_cast<ptrdiff_t>(10*state_cache_.size())) {
params->failed = true;
return false;
}
......@@ -1932,7 +1932,7 @@ int DFA::BuildAllStates() {
q.push_back(params.start);
// Flood to expand every state.
for (int i = 0; i < q.size(); i++) {
for (size_t i = 0; i < q.size(); i++) {
State* s = q[i];
for (int c = 0; c < 257; c++) {
State* ns = RunStateOnByteUnlocked(s, c);
......
......@@ -16,7 +16,7 @@ FilteredRE2::FilteredRE2()
}
FilteredRE2::~FilteredRE2() {
for (int i = 0; i < re2_vec_.size(); i++)
for (size_t i = 0; i < re2_vec_.size(); i++)
delete re2_vec_[i];
delete prefilter_tree_;
}
......@@ -46,7 +46,7 @@ void FilteredRE2::Compile(vector<string>* atoms) {
return;
}
for (int i = 0; i < re2_vec_.size(); i++) {
for (size_t i = 0; i < re2_vec_.size(); i++) {
Prefilter* prefilter = Prefilter::FromRE2(re2_vec_[i]);
prefilter_tree_->Add(prefilter);
}
......@@ -56,7 +56,7 @@ void FilteredRE2::Compile(vector<string>* atoms) {
}
int FilteredRE2::SlowFirstMatch(const StringPiece& text) const {
for (int i = 0; i < re2_vec_.size(); i++)
for (size_t i = 0; i < re2_vec_.size(); i++)
if (RE2::PartialMatch(text, *re2_vec_[i]))
return i;
return -1;
......@@ -70,7 +70,7 @@ int FilteredRE2::FirstMatch(const StringPiece& text,
}
vector<int> regexps;
prefilter_tree_->RegexpsGivenStrings(atoms, &regexps);
for (int i = 0; i < regexps.size(); i++)
for (size_t i = 0; i < regexps.size(); i++)
if (RE2::PartialMatch(text, *re2_vec_[regexps[i]]))
return regexps[i];
return -1;
......@@ -83,7 +83,7 @@ bool FilteredRE2::AllMatches(
matching_regexps->clear();
vector<int> regexps;
prefilter_tree_->RegexpsGivenStrings(atoms, &regexps);
for (int i = 0; i < regexps.size(); i++)
for (size_t i = 0; i < regexps.size(); i++)
if (RE2::PartialMatch(text, *re2_vec_[regexps[i]]))
matching_regexps->push_back(regexps[i]);
return !matching_regexps->empty();
......
......@@ -246,9 +246,9 @@ const CaseFold* LookupCaseFold(const CaseFold *f, int n, Rune r) {
// Binary search for entry containing r.
while (n > 0) {
int m = n/2;
if (f[m].lo <= r && r <= f[m].hi)
if (static_cast<Rune>(f[m].lo) <= r && r <= static_cast<Rune>(f[m].hi))
return &f[m];
if (r < f[m].lo) {
if (r < static_cast<Rune>(f[m].lo)) {
n = m;
} else {
f += m+1;
......@@ -305,7 +305,7 @@ Rune ApplyFold(const CaseFold *f, Rune r) {
// CycleFoldRune('?') = '?'
Rune CycleFoldRune(Rune r) {
const CaseFold* f = LookupCaseFold(unicode_casefold, num_unicode_casefold, r);
if (f == NULL || r < f->lo)
if (f == NULL || r < static_cast<Rune>(f->lo))
return r;
return ApplyFold(f, r);
}
......@@ -330,7 +330,7 @@ static void AddFoldedRange(CharClassBuilder* cc, Rune lo, Rune hi, int depth) {
const CaseFold* f = LookupCaseFold(unicode_casefold, num_unicode_casefold, lo);
if (f == NULL) // lo has no fold, nor does anything above lo
break;
if (lo < f->lo) { // lo has no fold; next rune with a fold is f->lo
if (lo < static_cast<Rune>(f->lo)) { // lo has no fold; next rune with a fold is f->lo
lo = f->lo;
continue;
}
......@@ -716,7 +716,7 @@ void Regexp::RemoveLeadingString(Regexp* re, int n) {
Regexp* stk[4];
int d = 0;
while (re->op() == kRegexpConcat) {
if (d < arraysize(stk))
if (static_cast<size_t>(d) < arraysize(stk))
stk[d++] = re;
re = re->sub()[0];
}
......@@ -1468,12 +1468,12 @@ static void AddUGroup(CharClassBuilder *cc, const UGroup *g, int sign,
}
int next = 0;
for (int i = 0; i < g->nr16; i++) {
if (next < g->r16[i].lo)
if (next < static_cast<Rune>(g->r16[i].lo))
cc->AddRangeFlags(next, g->r16[i].lo - 1, parse_flags);
next = g->r16[i].hi + 1;
}
for (int i = 0; i < g->nr32; i++) {
if (next < g->r32[i].lo)
if (next < static_cast<Rune>(g->r32[i].lo))
cc->AddRangeFlags(next, g->r32[i].lo - 1, parse_flags);
next = g->r32[i].hi + 1;
}
......@@ -1540,7 +1540,7 @@ ParseStatus ParseUnicodeGroup(StringPiece* s, Regexp::ParseFlags parse_flags,
} else {
// Name is in braces. Look for closing }
int end = s->find('}', 0);
if (end == s->npos) {
if (end == static_cast<int>(s->npos)) {
if (!IsValidUTF8(seq, status))
return kParseError;
status->set_code(kRegexpBadCharRange);
......@@ -1823,7 +1823,7 @@ bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
if (t.size() > 2 && t[0] == 'P' && t[1] == '<') {
// Pull out name.
int end = t.find('>', 2);
if (end == t.npos) {
if (end == static_cast<int>(t.npos)) {
if (!IsValidUTF8(*s, status_))
return false;
status_->set_code(kRegexpBadNamedCapture);
......
......@@ -31,7 +31,7 @@ Prefilter::Prefilter(Op op) {
Prefilter::~Prefilter() {
VLOG(10) << "Deleted: " << alloc_id_;
if (subs_) {
for (int i = 0; i < subs_->size(); i++)
for (size_t i = 0; i < subs_->size(); i++)
delete (*subs_)[i];
delete subs_;
subs_ = NULL;
......@@ -100,7 +100,7 @@ Prefilter* Prefilter::AndOr(Op op, Prefilter* a, Prefilter* b) {
// If a and b match op, merge their contents.
if (a->op() == op && b->op() == op) {
for (int i = 0; i < b->subs()->size(); i++) {
for (size_t i = 0; i < b->subs()->size(); i++) {
Prefilter* bb = (*b->subs())[i];
a->subs()->push_back(bb);
}
......@@ -176,7 +176,7 @@ static Rune ToLowerRune(Rune r) {
}
const CaseFold *f = LookupCaseFold(unicode_tolower, num_unicode_tolower, r);
if (f == NULL || r < f->lo)
if (f == NULL || r < static_cast<Rune>(f->lo))
return r;
return ApplyFold(f, r);
}
......@@ -669,7 +669,7 @@ string Prefilter::DebugString() const {
return "";
case AND: {
string s = "";
for (int i = 0; i < subs_->size(); i++) {
for (size_t i = 0; i < subs_->size(); i++) {
if (i > 0)
s += " ";
Prefilter* sub = (*subs_)[i];
......@@ -679,7 +679,7 @@ string Prefilter::DebugString() const {
}
case OR: {
string s = "(";
for (int i = 0; i < subs_->size(); i++) {
for (size_t i = 0; i < subs_->size(); i++) {
if (i > 0)
s += "|";
Prefilter* sub = (*subs_)[i];
......
......@@ -19,10 +19,10 @@ PrefilterTree::PrefilterTree()
}
PrefilterTree::~PrefilterTree() {
for (int i = 0; i < prefilter_vec_.size(); i++)
for (size_t i = 0; i < prefilter_vec_.size(); i++)
delete prefilter_vec_[i];
for (int i = 0; i < entries_.size(); i++)
for (size_t i = 0; i < entries_.size(); i++)
delete entries_[i].parents;
}
......@@ -43,12 +43,12 @@ static bool KeepPart(Prefilter* prefilter, int level) {
case Prefilter::ATOM:
return prefilter->atom().size() >=
FLAGS_filtered_re2_min_atom_len;
static_cast<size_t>(FLAGS_filtered_re2_min_atom_len);
case Prefilter::AND: {
int j = 0;
vector<Prefilter*>* subs = prefilter->subs();
for (int i = 0; i < subs->size(); i++)
for (size_t i = 0; i < subs->size(); i++)
if (KeepPart((*subs)[i], level + 1))
(*subs)[j++] = (*subs)[i];
else
......@@ -59,7 +59,7 @@ static bool KeepPart(Prefilter* prefilter, int level) {
}
case Prefilter::OR:
for (int i = 0; i < prefilter->subs()->size(); i++)
for (size_t i = 0; i < prefilter->subs()->size(); i++)
if (!KeepPart((*prefilter->subs())[i], level + 1))
return false;
return true;
......@@ -101,7 +101,7 @@ void PrefilterTree::Compile(vector<string>* atom_vec) {
// no longer necessary for their parent to trigger; that is, we do
// not miss out on any regexps triggering by getting rid of a
// prefilter node.
for (int i = 0; i < entries_.size(); i++) {
for (size_t i = 0; i < entries_.size(); i++) {
StdIntMap* parents = entries_[i].parents;
if (parents->size() > 8) {
// This one triggers too many things. If all the parents are AND
......@@ -146,7 +146,7 @@ string PrefilterTree::NodeString(Prefilter* node) const {
if (node->op() == Prefilter::ATOM) {
s += node->atom();
} else {
for (int i = 0; i < node->subs()->size() ; i++) {
for (size_t i = 0; i < node->subs()->size() ; i++) {
if (i > 0)
s += ',';
s += Itoa((*node->subs())[i]->unique_id());
......@@ -163,7 +163,7 @@ void PrefilterTree::AssignUniqueIds(vector<string>* atom_vec) {
vector<Prefilter*> v;
// Add the top level nodes of each regexp prefilter.
for (int i = 0; i < prefilter_vec_.size(); i++) {
for (size_t i = 0; i < prefilter_vec_.size(); i++) {
Prefilter* f = prefilter_vec_[i];
if (f == NULL)
unfiltered_.push_back(i);
......@@ -174,13 +174,13 @@ void PrefilterTree::AssignUniqueIds(vector<string>* atom_vec) {
}
// Now add all the descendant nodes.
for (int i = 0; i < v.size(); i++) {
for (size_t i = 0; i < v.size(); i++) {
Prefilter* f = v[i];
if (f == NULL)
continue;
if (f->op() == Prefilter::AND || f->op() == Prefilter::OR) {
const vector<Prefilter*>& subs = *f->subs();
for (int j = 0; j < subs.size(); j++)
for (size_t j = 0; j < subs.size(); j++)
v.push_back(subs[j]);
}
}
......@@ -245,7 +245,7 @@ void PrefilterTree::AssignUniqueIds(vector<string>* atom_vec) {
case Prefilter::OR:
case Prefilter::AND: {
set<int> uniq_child;
for (int j = 0; j < prefilter->subs()->size() ; j++) {
for (size_t j = 0; j < prefilter->subs()->size() ; j++) {
Prefilter* child = (*prefilter->subs())[j];
Prefilter* canonical = CanonicalNode(child);
if (canonical == NULL) {
......@@ -268,7 +268,7 @@ void PrefilterTree::AssignUniqueIds(vector<string>* atom_vec) {
}
// For top level nodes, populate regexp id.
for (int i = 0; i < prefilter_vec_.size(); i++) {
for (size_t i = 0; i < prefilter_vec_.size(); i++) {
if (prefilter_vec_[i] == NULL)
continue;
int id = CanonicalNode(prefilter_vec_[i])->unique_id();
......@@ -285,13 +285,13 @@ void PrefilterTree::RegexpsGivenStrings(
regexps->clear();
if (!compiled_) {
LOG(WARNING) << "Compile() not called";
for (int i = 0; i < prefilter_vec_.size(); ++i)
for (size_t i = 0; i < prefilter_vec_.size(); ++i)
regexps->push_back(i);
} else {
if (!prefilter_vec_.empty()) {
IntMap regexps_map(prefilter_vec_.size());
vector<int> matched_atom_ids;
for (int j = 0; j < matched_atoms.size(); j++) {
for (size_t j = 0; j < matched_atoms.size(); j++) {
matched_atom_ids.push_back(atom_index_to_id_[matched_atoms[j]]);
VLOG(10) << "Atom id:" << atom_index_to_id_[matched_atoms[j]];
}
......@@ -311,13 +311,13 @@ void PrefilterTree::PropagateMatch(const vector<int>& atom_ids,
IntMap* regexps) const {
IntMap count(entries_.size());
IntMap work(entries_.size());
for (int i = 0; i < atom_ids.size(); i++)
for (size_t i = 0; i < atom_ids.size(); i++)
work.set(atom_ids[i], 1);
for (IntMap::iterator it = work.begin(); it != work.end(); ++it) {
const Entry& entry = entries_[it->index()];
VLOG(10) << "Processing: " << it->index();
// Record regexps triggered.
for (int i = 0; i < entry.regexps.size(); i++) {
for (size_t i = 0; i < entry.regexps.size(); i++) {
VLOG(10) << "Regexp triggered: " << entry.regexps[i];
regexps->set(entry.regexps[i], 1);
}
......@@ -357,7 +357,7 @@ void PrefilterTree::PrintDebugInfo() {
VLOG(10) << "#Unique Atoms: " << atom_index_to_id_.size();
VLOG(10) << "#Unique Nodes: " << entries_.size();
for (int i = 0; i < entries_.size(); ++i) {
for (size_t i = 0; i < entries_.size(); ++i) {
StdIntMap* parents = entries_[i].parents;
const vector<int>& regexps = entries_[i].regexps;
VLOG(10) << "EntryId: " << i
......@@ -382,7 +382,7 @@ string PrefilterTree::DebugNodeString(Prefilter* node) const {
// Adding the operation disambiguates AND and OR nodes.
node_string += node->op() == Prefilter::AND ? "AND" : "OR";
node_string += "(";
for (int i = 0; i < node->subs()->size() ; i++) {
for (size_t i = 0; i < node->subs()->size() ; i++) {
if (i > 0)
node_string += ',';
node_string += Itoa((*node->subs())[i]->unique_id());
......
......@@ -356,7 +356,7 @@ bool RE2::Replace(string *str,
const StringPiece& rewrite) {
StringPiece vec[kVecSize];
int nvec = 1 + MaxSubmatch(rewrite);
if (nvec > arraysize(vec))
if (static_cast<size_t>(nvec) > arraysize(vec))
return false;
if (!re.Match(*str, 0, str->size(), UNANCHORED, vec, nvec))
return false;
......@@ -376,7 +376,7 @@ int RE2::GlobalReplace(string *str,
const StringPiece& rewrite) {
StringPiece vec[kVecSize];
int nvec = 1 + MaxSubmatch(rewrite);
if (nvec > arraysize(vec))
if (static_cast<size_t>(nvec) > arraysize(vec))
return false;
const char* p = str->data();
......@@ -417,7 +417,7 @@ bool RE2::Extract(const StringPiece &text,
string *out) {
StringPiece vec[kVecSize];
int nvec = 1 + MaxSubmatch(rewrite);
if (nvec > arraysize(vec))
if (static_cast<size_t>(nvec) > arraysize(vec))
return false;
if (!re.Match(text, 0, text.size(), UNANCHORED, vec, nvec))
......@@ -807,7 +807,7 @@ bool RE2::DoMatch(const StringPiece& text,
StringPiece stkvec[kVecSize];
StringPiece* heapvec = NULL;
if (nvec <= arraysize(stkvec)) {
if (static_cast<size_t>(nvec) <= arraysize(stkvec)) {
vec = stkvec;
} else {
vec = new StringPiece[nvec];
......
......@@ -849,7 +849,7 @@ void CharClassBuilder::Negate() {
}
ranges_.clear();
for (int i = 0; i < v.size(); i++)
for (size_t i = 0; i < v.size(); i++)
ranges_.insert(v[i]);
upper_ = AlphaMask & ~upper_;
......@@ -920,7 +920,7 @@ CharClass* CharClassBuilder::GetCharClass() {
for (iterator it = begin(); it != end(); ++it)
cc->ranges_[n++] = *it;
cc->nranges_ = n;
DCHECK_LE(n, ranges_.size());
DCHECK_LE(n, static_cast<int>(ranges_.size()));
cc->nrunes_ = nrunes_;
cc->folds_ascii_ = FoldsASCII();
return cc;
......
......@@ -20,7 +20,7 @@ RE2::Set::Set(const RE2::Options& options, RE2::Anchor anchor) {
}
RE2::Set::~Set() {
for (int i = 0; i < re_.size(); i++)
for (size_t i = 0; i < re_.size(); i++)
re_[i]->Decref();
delete prog_;
}
......
......@@ -71,7 +71,7 @@ void UnsafeArena::Reset() {
UnsafeArena::AllocatedBlock* UnsafeArena::AllocNewBlock(const size_t block_size) {
AllocatedBlock *block;
// Find the next block.
if ( blocks_alloced_ < arraysize(first_blocks_) ) {
if (static_cast<size_t>(blocks_alloced_) < arraysize(first_blocks_) ) {
// Use one of the pre-allocated blocks
block = &first_blocks_[blocks_alloced_++];
} else { // oops, out of space, move to the vector
......@@ -119,7 +119,7 @@ void* UnsafeArena::GetMemoryFallback(const size_t size, const int align) {
if (overage) {
const int waste = align - overage;
freestart_ += waste;
if (waste < remaining_) {
if (waste < static_cast<int>(remaining_)) {
remaining_ -= waste;
} else {
remaining_ = 0;
......
......@@ -347,7 +347,7 @@ int PCRE::GlobalReplace(string *str,
int count = 0;
int vec[kVecSize];
string out;
int start = 0;
size_t start = 0;
bool last_match_was_empty_string = false;
for (; start <= str->length();) {
......@@ -378,7 +378,7 @@ int PCRE::GlobalReplace(string *str,
break;
}
int matchstart = vec[0], matchend = vec[1];
assert(matchstart >= start);
assert(matchstart >= static_cast<int>(start));
assert(matchend >= matchstart);
out.append(*str, start, matchstart - start);
......@@ -550,6 +550,9 @@ int PCRE::TryMatch(const StringPiece& text,
return rc;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
bool PCRE::DoMatchImpl(const StringPiece& text,
Anchor anchor,
int* consumed,
......@@ -589,6 +592,8 @@ bool PCRE::DoMatchImpl(const StringPiece& text,
return true;
}
#pragma GCC diagnostic pop
bool PCRE::DoMatch(const StringPiece& text,
Anchor anchor,
int* consumed,
......
......@@ -294,7 +294,7 @@ template<typename Value>
bool SparseArray<Value>::has_index(int i) const {
DCHECK_GE(i, 0);
DCHECK_LT(i, max_size_);
if (static_cast<uint>(i) >= max_size_) {
if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
return false;
}
// Unsigned comparison avoids checking sparse_to_dense_[i] < 0.
......@@ -306,7 +306,7 @@ bool SparseArray<Value>::has_index(int i) const {
template<typename Value>
typename SparseArray<Value>::iterator SparseArray<Value>::set(int i, Value v) {
DebugCheckInvariants();
if (static_cast<uint>(i) >= max_size_) {
if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
// Semantically, end() would be better here, but we already know
// the user did something stupid, so begin() insulates them from
// dereferencing an invalid pointer.
......@@ -368,7 +368,7 @@ template<typename Value>
typename SparseArray<Value>::iterator
SparseArray<Value>::set_new(int i, Value v) {
DebugCheckInvariants();
if (static_cast<uint>(i) >= max_size_) {
if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
// Semantically, end() would be better here, but we already know
// the user did something stupid, so begin() insulates them from
// dereferencing an invalid pointer.
......
......@@ -128,7 +128,7 @@ class SparseSet {
bool contains(int i) const {
DCHECK_GE(i, 0);
DCHECK_LT(i, max_size_);
if (static_cast<uint>(i) >= max_size_) {
if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
return false;
}
// Unsigned comparison avoids checking sparse_to_dense_[i] < 0.
......@@ -145,7 +145,7 @@ class SparseSet {
// Set the value at the new index i to v.
// Fast but unsafe: only use if contains(i) is false.
void insert_new(int i) {
if (static_cast<uint>(i) >= max_size_) {
if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
// Semantically, end() would be better here, but we already know
// the user did something stupid, so begin() insulates them from
// dereferencing an invalid pointer.
......
......@@ -46,7 +46,7 @@ int StringPiece::find(const StringPiece& s, size_type pos) const {
const char* result = std::search(ptr_ + pos, ptr_ + length_,
s.ptr_, s.ptr_ + s.length_);
const size_type xpos = result - ptr_;
return xpos + s.length_ <= length_ ? xpos : npos;
return xpos + s.length_ <= static_cast<size_type>(length_) ? xpos : npos;
}
int StringPiece::find(char c, size_type pos) const {
......@@ -79,7 +79,7 @@ int StringPiece::rfind(char c, size_type pos) const {
}
StringPiece StringPiece::substr(size_type pos, size_type n) const {
if (pos > length_) pos = length_;
if (pos > static_cast<size_type>(length_)) pos = length_;
if (n > length_ - pos) n = length_ - pos;
return StringPiece(ptr_ + pos, n);
}
......
......@@ -18,7 +18,7 @@ static void StringAppendV(string* dst, const char* format, va_list ap) {
int result = vsnprintf(space, sizeof(space), format, backup_ap);
va_end(backup_ap);
if ((result >= 0) && (result < sizeof(space))) {
if ((result >= 0) && (static_cast<size_t>(result) < sizeof(space))) {
// It fit
dst->append(space, result);
return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册