Fix a possible out of bounds bug in vectors
diff --git a/include/bc.h b/include/bc.h
index 959a275..4eaec14 100644
--- a/include/bc.h
+++ b/include/bc.h
@@ -60,6 +60,8 @@
BC_STATUS_NO_LIMIT,
BC_STATUS_INVALID_LIMIT,
+ BC_STATUS_VEC_OUT_OF_BOUNDS,
+
BC_STATUS_VECO_OUT_OF_BOUNDS,
BC_STATUS_VECO_ITEM_EXISTS,
diff --git a/src/bc/bc.c b/src/bc/bc.c
index caa7f4f..3552e2c 100644
--- a/src/bc/bc.c
+++ b/src/bc/bc.c
@@ -48,6 +48,9 @@
"vector",
+ "ordered vector",
+ "ordered vector",
+
"Lex",
"Lex",
"Lex",
@@ -123,6 +126,9 @@
"one or more limits not specified",
"invalid limit; this is a bug in bc",
+ "index is out of bounds for the vector and error was not caught; "
+ "this is probably a bug in bc",
+
"index is out of bounds for the ordered vector and error was not caught; "
"this is probably a bug in bc",
"item already exists in ordered vector and error was not caught; "
diff --git a/src/bc/vector.c b/src/bc/vector.c
index 94d4af7..71a88bc 100644
--- a/src/bc/vector.c
+++ b/src/bc/vector.c
@@ -161,6 +161,8 @@
return BC_STATUS_INVALID_PARAM;
}
+ if (!vec->len) return BC_STATUS_VEC_OUT_OF_BOUNDS,
+
--vec->len;
if (vec->dtor) vec->dtor(vec->array + (vec->size * vec->len));