commit 8ace2b9ed42d91ce96f358103cf1b3d94f613fd9
Author: Jim Meyering <meyering(a)redhat.com>
Date: Fri May 6 14:47:35 2011 +0200
avoid theoretical integer overflow and -Wsign-compare warning
* meta.cpp (class AttrList) [idx]: Change type: s/int/size_t/,
This variable is only ever incremented and used as a vector index.
meta.cpp | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/meta.cpp b/meta.cpp
index 3cf6f57..b88b8c3 100644
--- a/meta.cpp
+++ b/meta.cpp
@@ -611,7 +611,7 @@ public:
int Next (const char **, const char **);
BSONObj obj;
vector<BSONElement> vec;
- int idx;
+ size_t idx;
};
AttrList::AttrList (BSONObj &bo)
@@ -627,7 +627,12 @@ AttrList::Next (const char **name, const char **value)
BSONElement elem;
while (idx < vec.size()) {
- elem = vec[idx++];
+ elem = vec[idx];
+
+ // Do not wrap back to 0 when vec.size is SIZE_MAX.
+ if (idx != vec.size())
+ idx++;
+
if (elem.type() == String) {
*name = elem.fieldName();
*value = elem.String().c_str();
Show replies by date