diff --git a/lang/m2/libm2/LIST b/lang/m2/libm2/LIST index 4294f16a6..7e3a15efd 100644 --- a/lang/m2/libm2/LIST +++ b/lang/m2/libm2/LIST @@ -38,10 +38,10 @@ confarray.c load.c blockmove.c stackprio.c -ChkCards.e +ucheck.c +rcka.c +rcku.c +rcki.c +rckul.c +rckil.c EM.e -rcka.e -rcku.e -rcki.e -rckul.e -rckil.e diff --git a/lang/m2/libm2/rcka.c b/lang/m2/libm2/rcka.c new file mode 100644 index 000000000..6178bd6fb --- /dev/null +++ b/lang/m2/libm2/rcka.c @@ -0,0 +1,25 @@ +/* + * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * + * Module: range checks for INTEGER, now for array indexing + * Author: Ceriel J.H. Jacobs + * Version: $Header$ +*/ + +#include + +extern TRP(); + +struct array_descr { + int lbound; + int n_elts_min_one; + unsigned size; +}; + +rcka(descr, indx) + struct array_descr *descr; +{ + if (indx < 0 || indx > descr->n_elts_min_one) TRP(EARRAY); +} diff --git a/lang/m2/libm2/rcki.c b/lang/m2/libm2/rcki.c new file mode 100644 index 000000000..289646170 --- /dev/null +++ b/lang/m2/libm2/rcki.c @@ -0,0 +1,23 @@ +/* + * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * + * Module: range checks for INTEGER + * Author: Ceriel J.H. Jacobs + * Version: $Header$ +*/ + +#include + +extern TRP(); + +struct range_descr { + int low, high; +}; + +rcki(descr, val) + struct range_descr *descr; +{ + if (val < descr->low || val > descr->high) TRP(ERANGE); +} diff --git a/lang/m2/libm2/rckil.c b/lang/m2/libm2/rckil.c new file mode 100644 index 000000000..cf43a9842 --- /dev/null +++ b/lang/m2/libm2/rckil.c @@ -0,0 +1,24 @@ +/* + * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * + * Module: range checks for LONGINT + * Author: Ceriel J.H. Jacobs + * Version: $Header$ +*/ + +#include + +extern TRP(); + +struct range_descr { + long low, high; +}; + +rcki(descr, val) + struct range_descr *descr; + long val; +{ + if (val < descr->low || val > descr->high) TRP(ERANGE); +} diff --git a/lang/m2/libm2/rcku.c b/lang/m2/libm2/rcku.c new file mode 100644 index 000000000..5ca4208cf --- /dev/null +++ b/lang/m2/libm2/rcku.c @@ -0,0 +1,24 @@ +/* + * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * + * Module: range checks for CARDINAL + * Author: Ceriel J.H. Jacobs + * Version: $Header$ +*/ + +#include + +extern TRP(); + +struct range_descr { + unsigned low, high; +}; + +rcki(descr, val) + struct range_descr *descr; + unsigned val; +{ + if (val < descr->low || val > descr->high) TRP(ERANGE); +} diff --git a/lang/m2/libm2/rckul.c b/lang/m2/libm2/rckul.c new file mode 100644 index 000000000..4a5e4c9a3 --- /dev/null +++ b/lang/m2/libm2/rckul.c @@ -0,0 +1,24 @@ +/* + * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * + * Module: range checks for LONGCARD + * Author: Ceriel J.H. Jacobs + * Version: $Header$ +*/ + +#include + +extern TRP(); + +struct range_descr { + unsigned long low, high; +}; + +rcki(descr, val) + struct range_descr *descr; + unsigned long val; +{ + if (val < descr->low || val > descr->high) TRP(ERANGE); +} diff --git a/lang/m2/libm2/ucheck.c b/lang/m2/libm2/ucheck.c new file mode 100644 index 000000000..8c56b37bb --- /dev/null +++ b/lang/m2/libm2/ucheck.c @@ -0,0 +1,65 @@ +/* + * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * + * Module: CARDINAL operations with overflow checking + * Author: Ceriel J.H. Jacobs + * Version: $Header$ +*/ + +#ifndef EM_WSIZE +#define EM_WSIZE _EM_WSIZE +#endif +#ifndef EM_LSIZE +#define EM_LSIZE _EM_LSIZE +#endif + +#include + +#define MAXCARD ((unsigned)-1) +#if EM_WSIZE < EM_LSIZE +#define MAXLONGCARD ((unsigned long) -1L) +#endif + +adduchk(a,b) + unsigned a,b; +{ + if (MAXCARD - a > b) TRP(M2_UOVFL); +} + +#if EM_WSIZE < EM_LSIZE +addulchk(a,b) + unsigned long a,b; +{ + if (MAXLONGCARD - a > b) TRP(M2_UOVFL); +} +#endif + +muluchk(a,b) + unsigned a,b; +{ + if (a != 0 && MAXCARD/a < b) TRP(M2_UOVFL); +} + +#if EM_WSIZE < EM_LSIZE +mululchk(a,b) + unsigned long a,b; +{ + if (a != 0 && MAXLONGCARD/a < b) TRP(M2_UOVFL); +} +#endif + +subuchk(a,b) + unsigned a,b; +{ + if (b < a) TRP(M2_UOVFL); +} + +#if EM_WSIZE < EM_LSIZE +subulchk(a,b) + unsigned long a,b; +{ + if (b < a) TRP(M2_UOVFL); +} +#endif