1995-04-21 06:47:35 +04:00
|
|
|
/* $NetBSD: bounds.h,v 1.3 1995/04/21 02:47:47 briggs Exp $ */
|
1994-10-26 11:45:48 +03:00
|
|
|
|
1994-07-08 11:55:46 +04:00
|
|
|
#if defined(CHECKBOUNDS)
|
|
|
|
|
|
|
|
#undef CHECKBOUNDS
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/* This requires ANSI C stringification. */
|
|
|
|
#define CHECKBOUNDS(a, i) { \
|
|
|
|
if ( (((a) + (i)) < (a)) || \
|
|
|
|
(((a) + (i)) >= ((a) + (sizeof(a) / sizeof(*(a))))) ) { \
|
|
|
|
printf("index " #i " (%d) exceeded bounds of " #a \
|
|
|
|
", '%s' line %d.\n", (i), __FILE__, __LINE__); \
|
|
|
|
printf("halting...\n"); \
|
|
|
|
/*asm(" stop #0x2700");*/ \
|
|
|
|
} \
|
|
|
|
}
|
1994-07-08 11:55:46 +04:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
#define CHECKPOINTER(a, p) { \
|
|
|
|
if ( ((p) < (a)) || \
|
|
|
|
((p) >= ((a) + (sizeof(a) / sizeof(*(a))))) ) { \
|
|
|
|
printf("pointer " #p " (0x%X) exceeded bounds of " #a \
|
|
|
|
" (0x%X), '%s' line %d.\n", \
|
|
|
|
(p), (a), __FILE__, __LINE__); \
|
|
|
|
printf("halting...\n"); \
|
|
|
|
/*asm(" stop #0x2700");*/ \
|
|
|
|
} \
|
|
|
|
}
|
1994-07-08 11:55:46 +04:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
#else /* !defined(CHECKBOUNDS) */
|
1994-07-08 11:55:46 +04:00
|
|
|
|
|
|
|
#define CHECKBOUNDS(a, i)
|
|
|
|
#define CHECKPOINTER(a, p)
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
#endif /* defined(CHECKBOUNDS) */
|