From 5abc4ce01a4ed68b9a2daac287a7b0d4cb526d05 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 23 Jun 2017 17:50:46 +0800 Subject: [PATCH] fix warnings (#298) --- Box2D/Collision/b2CollideCircle.cpp | 2 +- Box2D/Dynamics/Joints/b2WheelJoint.cpp | 4 ++-- Box2D/Dynamics/b2Island.cpp | 2 +- clipper/clipper.cpp | 2 +- flatbuffers/flatbuffers.h | 1 + flatbuffers/flatc.cpp | 6 +++--- flatbuffers/idl.h | 4 ++-- flatbuffers/idl_gen_fbs.cpp | 12 ++++++------ flatbuffers/idl_parser.cpp | 12 ++++++------ poly2tri/sweep/sweep.cc | 11 +++++------ rapidxml/rapidxml_sax3.hpp | 10 ---------- recast/DetourCrowd/DetourObstacleAvoidance.cpp | 1 - recast/fastlz/fastlz.c | 10 +++++----- 13 files changed, 33 insertions(+), 44 deletions(-) diff --git a/Box2D/Collision/b2CollideCircle.cpp b/Box2D/Collision/b2CollideCircle.cpp index 4181fd47cb..b5c68defd9 100644 --- a/Box2D/Collision/b2CollideCircle.cpp +++ b/Box2D/Collision/b2CollideCircle.cpp @@ -138,7 +138,7 @@ void b2CollidePolygonAndCircle( else { b2Vec2 faceCenter = 0.5f * (v1 + v2); - float32 separation = b2Dot(cLocal - faceCenter, normals[vertIndex1]); + separation = b2Dot(cLocal - faceCenter, normals[vertIndex1]); if (separation > radius) { return; diff --git a/Box2D/Dynamics/Joints/b2WheelJoint.cpp b/Box2D/Dynamics/Joints/b2WheelJoint.cpp index c9f6de6005..30130b63f1 100644 --- a/Box2D/Dynamics/Joints/b2WheelJoint.cpp +++ b/Box2D/Dynamics/Joints/b2WheelJoint.cpp @@ -141,14 +141,14 @@ void b2WheelJoint::InitVelocityConstraints(const b2SolverData& data) float32 omega = 2.0f * b2_pi * m_frequencyHz; // Damping coefficient - float32 d = 2.0f * m_springMass * m_dampingRatio * omega; + float32 d2 = 2.0f * m_springMass * m_dampingRatio * omega; // Spring stiffness float32 k = m_springMass * omega * omega; // magic formulas float32 h = data.step.dt; - m_gamma = h * (d + h * k); + m_gamma = h * (d2 + h * k); if (m_gamma > 0.0f) { m_gamma = 1.0f / m_gamma; diff --git a/Box2D/Dynamics/b2Island.cpp b/Box2D/Dynamics/b2Island.cpp index d46589dee9..c128fc0c4e 100644 --- a/Box2D/Dynamics/b2Island.cpp +++ b/Box2D/Dynamics/b2Island.cpp @@ -312,7 +312,7 @@ void b2Island::Solve(b2Profile* profile, const b2TimeStep& step, const b2Vec2& g bool contactsOkay = contactSolver.SolvePositionConstraints(); bool jointsOkay = true; - for (int32 i = 0; i < m_jointCount; ++i) + for (int32 j = 0; j < m_jointCount; ++j) { bool jointOkay = m_joints[i]->SolvePositionConstraints(solverData); jointsOkay = jointsOkay && jointOkay; diff --git a/clipper/clipper.cpp b/clipper/clipper.cpp index 9d158584a7..4615bfec5b 100644 --- a/clipper/clipper.cpp +++ b/clipper/clipper.cpp @@ -3242,7 +3242,7 @@ void Clipper::BuildResult(Paths &polys) int cnt = PointCount(p); if (cnt < 2) continue; pg.reserve(cnt); - for (int i = 0; i < cnt; ++i) + for (int j = 0; j < cnt; ++j) { pg.push_back(p->Pt); p = p->Prev; diff --git a/flatbuffers/flatbuffers.h b/flatbuffers/flatbuffers.h index 191f70b92e..a042534569 100644 --- a/flatbuffers/flatbuffers.h +++ b/flatbuffers/flatbuffers.h @@ -297,6 +297,7 @@ struct String : public Vector { // with custom allocation (see the FlatBufferBuilder constructor). class simple_allocator { public: + virtual ~simple_allocator(){} virtual uint8_t *allocate(size_t size) const { return new uint8_t[size]; } virtual void deallocate(uint8_t *p) const { delete[] p; } }; diff --git a/flatbuffers/flatc.cpp b/flatbuffers/flatc.cpp index 52d8a7c7cd..72fe5149ae 100755 --- a/flatbuffers/flatc.cpp +++ b/flatbuffers/flatc.cpp @@ -152,9 +152,9 @@ int main(int argc, const char *argv[]) { proto_mode = true; any_generator = true; } else { - for (size_t i = 0; i < num_generators; ++i) { - if(opt == generators[i].opt) { - generator_enabled[i] = true; + for (size_t j = 0; j < num_generators; ++j) { + if(opt == generators[j].opt) { + generator_enabled[j] = true; any_generator = true; goto found; } diff --git a/flatbuffers/idl.h b/flatbuffers/idl.h index f7b747cc4c..9a19a8d2a9 100644 --- a/flatbuffers/idl.h +++ b/flatbuffers/idl.h @@ -203,8 +203,8 @@ struct StructDef : public Definition { bytesize(0) {} - void PadLastField(size_t minalign) { - auto padding = PaddingBytes(bytesize, minalign); + void PadLastField(size_t _minalign) { + auto padding = PaddingBytes(bytesize, _minalign); bytesize += padding; if (fields.vec.size()) fields.vec.back()->padding = padding; } diff --git a/flatbuffers/idl_gen_fbs.cpp b/flatbuffers/idl_gen_fbs.cpp index 87603e6073..083775eba4 100644 --- a/flatbuffers/idl_gen_fbs.cpp +++ b/flatbuffers/idl_gen_fbs.cpp @@ -63,9 +63,9 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name, EnumDef &enum_def = **it; schema += "enum " + enum_def.name + " : "; schema += GenType(enum_def.underlying_type) + " {\n"; - for (auto it = enum_def.vals.vec.begin(); - it != enum_def.vals.vec.end(); ++it) { - auto &ev = **it; + for (auto it2 = enum_def.vals.vec.begin(); + it2 != enum_def.vals.vec.end(); ++it2) { + auto &ev = **it2; schema += " " + ev.name + " = " + NumToString(ev.value) + ",\n"; } schema += "}\n\n"; @@ -75,9 +75,9 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name, it != parser.structs_.vec.end(); ++it) { StructDef &struct_def = **it; schema += "table " + struct_def.name + " {\n"; - for (auto it = struct_def.fields.vec.begin(); - it != struct_def.fields.vec.end(); ++it) { - auto &field = **it; + for (auto it2 = struct_def.fields.vec.begin(); + it2 != struct_def.fields.vec.end(); ++it2) { + auto &field = **it2; schema += " " + field.name + ":" + GenType(field.value.type); if (field.value.constant != "0") schema += " = " + field.value.constant; if (field.required) schema += " (required)"; diff --git a/flatbuffers/idl_parser.cpp b/flatbuffers/idl_parser.cpp index a326127622..e50169a1cb 100644 --- a/flatbuffers/idl_parser.cpp +++ b/flatbuffers/idl_parser.cpp @@ -745,8 +745,8 @@ void Parser::ParseEnum(bool is_union) { Expect('{'); if (is_union) enum_def.vals.Add("NONE", new EnumVal("NONE", 0)); do { - std::string name = attribute_; - std::vector dc = doc_comment_; + name = attribute_; + dc = doc_comment_; Expect(kTokenIdentifier); auto prevsize = enum_def.vals.vec.size(); auto value = enum_def.vals.vec.size() @@ -1105,10 +1105,10 @@ bool Parser::Parse(const char *source, const char **include_paths, for (auto it = enums_.vec.begin(); it != enums_.vec.end(); ++it) { auto &enum_def = **it; if (enum_def.is_union) { - for (auto it = enum_def.vals.vec.begin(); - it != enum_def.vals.vec.end(); - ++it) { - auto &val = **it; + for (auto it2 = enum_def.vals.vec.begin(); + it2 != enum_def.vals.vec.end(); + ++it2) { + auto &val = **it2; if (val.struct_def && val.struct_def->fixed) Error("only tables can be union elements: " + val.name); } diff --git a/poly2tri/sweep/sweep.cc b/poly2tri/sweep/sweep.cc index e31ffdec98..73a97fb21c 100644 --- a/poly2tri/sweep/sweep.cc +++ b/poly2tri/sweep/sweep.cc @@ -49,13 +49,12 @@ void Sweep::Triangulate(SweepContext& tcx) void Sweep::SweepPoints(SweepContext& tcx) { - for (size_t i = 1; i < tcx.point_count(); i++) { - Point& point = *tcx.GetPoint(i); - Node* node = &PointEvent(tcx, point); - for (unsigned int i = 0; i < point.edge_list.size(); i++) { - EdgeEvent(tcx, point.edge_list[i], node); + for (size_t i = 1; i < tcx.point_count(); i++) { + Point& point = *tcx.GetPoint(i); + Node* node = &PointEvent(tcx, point); + for (auto&& edge : point.edge_list) + EdgeEvent(tcx, edge, node); } - } } void Sweep::FinalizationPolygon(SweepContext& tcx) diff --git a/rapidxml/rapidxml_sax3.hpp b/rapidxml/rapidxml_sax3.hpp index 232913b5cb..663b15a5c3 100644 --- a/rapidxml/rapidxml_sax3.hpp +++ b/rapidxml/rapidxml_sax3.hpp @@ -569,9 +569,6 @@ namespace rapidxml return;// return 0; // Do not produce comment node } - // Remember value start - Ch *value = text; - // Skip until end of comment while (text[0] != Ch('-') || text[1] != Ch('-') || text[2] != Ch('>')) { @@ -596,9 +593,6 @@ namespace rapidxml template void parse_doctype(Ch *&text) { - // Remember value start - Ch *value = text; - // Skip to > while (*text != Ch('>')) { @@ -681,9 +675,6 @@ namespace rapidxml // Skip whitespace between pi target and pi skip(text, endptr_); - // Remember start of pi - Ch *value = text; - // Skip to '?>' while (text[0] != Ch('?') || text[1] != Ch('>')) { @@ -807,7 +798,6 @@ namespace rapidxml } // Skip until end of cdata - Ch *value = text; while (text[0] != Ch(']') || text[1] != Ch(']') || text[2] != Ch('>')) { if (!text[0]) diff --git a/recast/DetourCrowd/DetourObstacleAvoidance.cpp b/recast/DetourCrowd/DetourObstacleAvoidance.cpp index 55493c7ca5..4421785244 100644 --- a/recast/DetourCrowd/DetourObstacleAvoidance.cpp +++ b/recast/DetourCrowd/DetourObstacleAvoidance.cpp @@ -528,7 +528,6 @@ int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const flo const int nd = dtClamp(ndivs, 1, DT_MAX_PATTERN_DIVS); const int nr = dtClamp(nrings, 1, DT_MAX_PATTERN_RINGS); - const int nd2 = nd / 2; const float da = (1.0f/nd) * DT_PI*2; const float ca = cosf(da); const float sa = sinf(da); diff --git a/recast/fastlz/fastlz.c b/recast/fastlz/fastlz.c index 3c9d6f6f86..951cd7fc84 100644 --- a/recast/fastlz/fastlz.c +++ b/recast/fastlz/fastlz.c @@ -231,7 +231,7 @@ static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const void* input, int length, void* ref = htab[hval]; /* calculate distance to the match */ - distance = anchor - ref; + distance = (int)(anchor - ref); /* update hash table */ *hslot = anchor; @@ -301,7 +301,7 @@ static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const void* input, int length, void* /* length is biased, '1' means a match of 3 bytes */ ip -= 3; - len = ip - anchor; + len = (int)(ip - anchor); /* encode the match */ #if FASTLZ_LEVEL==2 @@ -414,7 +414,7 @@ static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const void* input, int length, void* *(flzuint8*)output |= (1 << 5); #endif - return op - (flzuint8*)output; + return (int)(op - (flzuint8*)output); } static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const void* input, int length, void* output, int maxout) @@ -538,14 +538,14 @@ static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const void* input, int length, void for(--ctrl; ctrl; ctrl--) *op++ = *ip++; - loop = FASTLZ_EXPECT_CONDITIONAL(ip < ip_limit); + loop = (int)FASTLZ_EXPECT_CONDITIONAL(ip < ip_limit); if(loop) ctrl = *ip++; } } while(FASTLZ_EXPECT_CONDITIONAL(loop)); - return op - (flzuint8*)output; + return (int)(op - (flzuint8*)output); } #endif /* !defined(FASTLZ_COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR) */