Browse Source

Fixed out of array bound

Tatsuhiro Tsujikawa 14 năm trước cách đây
mục cha
commit
f6f053cae1
1 tập tin đã thay đổi với 5 bổ sung2 xóa
  1. 5 2
      src/SegList.h

+ 5 - 2
src/SegList.h

@@ -103,11 +103,14 @@ public:
   T next()
   {
     T res;
-    if(index_ < segs_.size()) {
+    size_t len = segs_.size();
+    if(index_ < len) {
       res = val_++;
       if(val_ == segs_[index_].second) {
         ++index_;
-        val_ = segs_[index_].first;
+        if(index_ < len) {
+          val_ = segs_[index_].first;
+        }
       }
     } else {
       res = 0;