C run-time checking

Chris Torek chris at mimsy.UUCP
Tue Mar 15 23:57:36 AEST 1988


In article <763 at uvm-gen.UUCP> hartley at uvm-gen.UUCP (Stephen J. Hartley) writes:
>... Are there C compilers provided by any vendors that generate code
>to perform run-time checking ... such as checking an array subscript
>against the array bounds, checking a pointer for reasonable values
>before dereferencing it.

I have heard of two such compilers; one is called Safe-C and I cannot
recall the name of the other.  For some reason this is tied in with
a memory of a C interpreter that can dynamically either interpret or
compile code: a handy thing to have if you ever write buggy code :-) .

In general, pointer and array checking in C is difficult but not
impossible.  Every pointer must carry around three values (min, max,
and current), and some operations must be allowed while others must
be prevented.  E.g., the dpANS says that

	int foo[MAX], *p;
	for (p = &foo[0]; p < &foo[MAX]; p++)

is legal; hence, computing the address of foo[MAX] must be allowed,
while actually indirecting through *(foo+MAX) must not.  At least
one of those runtime-checking systems forced one to write

	for (p = &foo[0]; p <= &foo[MAX - 1]; p++)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list