瀏覽代碼

Fix constant out of bounds bug

gingerBill 5 年之前
父節點
當前提交
7e271310ff
共有 1 個文件被更改,包括 4 次插入5 次删除
  1. 4 5
      src/check_expr.cpp

+ 4 - 5
src/check_expr.cpp

@@ -3119,13 +3119,12 @@ bool check_index_value(CheckerContext *c, bool open_range, Ast *index_value, i64
 				}
 				if (value) *value = v;
 				bool out_of_bounds = false;
-				if (open_range) {
-					out_of_bounds = v >= max_count;
-				} else {
-					out_of_bounds = v >= max_count+1;
-				}
 				if (v < 0) {
 					out_of_bounds = true;
+				} else if (open_range) {
+					out_of_bounds = v > max_count;
+				} else {
+					out_of_bounds = v >= max_count;
 				}
 
 				if (out_of_bounds) {