summaryrefslogtreecommitdiff
path: root/gcc/varray.h
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2004-01-13 02:43:16 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2004-01-13 02:43:16 +0000
commit17ee7790ebfac94e22da60c8d4618acb90b11bbf (patch)
tree9b6873aeaaf57603e96839aaac2b6634121b7cfb /gcc/varray.h
parent282b8eed94ece927ed51e3a240360a046bc9b311 (diff)
downloadgcc-17ee7790ebfac94e22da60c8d4618acb90b11bbf.tar.gz
* varray.h (VARRAY_POP): Add checking variant, aborts on underflow.
(VARRAY_TOP): Use VARRAY_CHECK so the access is bounds-checked. * varray.c: No need to prototype error. (varray_check_failed): Wrap long string onto two lines. (varray_underflow): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@75786 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/varray.h')
-rw-r--r--gcc/varray.h23
1 files changed, 15 insertions, 8 deletions
diff --git a/gcc/varray.h b/gcc/varray.h
index 7cb9ff09855..9cc6ea5fffe 100644
--- a/gcc/varray.h
+++ b/gcc/varray.h
@@ -227,14 +227,27 @@ extern void varray_clear (varray_type);
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
extern void varray_check_failed (varray_type, size_t, const char *, int,
const char *) ATTRIBUTE_NORETURN;
+extern void varray_underflow (varray_type, const char *, int, const char *)
+ ATTRIBUTE_NORETURN;
#define VARRAY_CHECK(VA, N, T) __extension__ \
(*({ varray_type const _va = (VA); \
const size_t _n = (N); \
if (_n >= _va->num_elements) \
varray_check_failed (_va, _n, __FILE__, __LINE__, __FUNCTION__); \
&_va->data.T[_n]; }))
+
+#define VARRAY_POP(VA) do { \
+ varray_type const _va = (VA); \
+ if (_va->elements_used == 0) \
+ varray_underflow (_va, __FILE__, __LINE__, __FUNCTION__); \
+ else \
+ _va->elements_used--; \
+} while (0)
+
#else
#define VARRAY_CHECK(VA, N, T) ((VA)->data.T[N])
+/* Pop the top element of VA. */
+#define VARRAY_POP(VA) do { ((VA)->elements_used--); } while (0)
#endif
/* Push X onto VA. T is the name of the field in varray_data
@@ -248,14 +261,6 @@ extern void varray_check_failed (varray_type, size_t, const char *, int,
} \
while (0)
-/* Pop the top element of VA. */
-#define VARRAY_POP(VA) \
- ((VA)->elements_used--)
-
-/* Return the top element of VA. */
-#define VARRAY_TOP(VA, T) \
- ((VA)->data.T[(VA)->elements_used - 1])
-
#define VARRAY_CHAR(VA, N) VARRAY_CHECK (VA, N, c)
#define VARRAY_UCHAR(VA, N) VARRAY_CHECK (VA, N, uc)
#define VARRAY_SHORT(VA, N) VARRAY_CHECK (VA, N, s)
@@ -299,6 +304,8 @@ extern void varray_check_failed (varray_type, size_t, const char *, int,
#define VARRAY_PUSH_BB(VA, X) VARRAY_PUSH (VA, bb, X)
/* Return the last element of VA. */
+#define VARRAY_TOP(VA, T) VARRAY_CHECK(VA, (VA)->elements_used - 1, T)
+
#define VARRAY_TOP_CHAR(VA) VARRAY_TOP (VA, c)
#define VARRAY_TOP_UCHAR(VA) VARRAY_TOP (VA, uc)
#define VARRAY_TOP_SHORT(VA) VARRAY_TOP (VA, s)