MODULE routines rely heavily on the accuracy
of the information in the attribute table. If this information is
incorrect, unpredictable results can occur (including a system crash).
Consider an example
routine
xyz
that expects two arguments: an
integer and a pointer. The integer is a code indicating what action
takes place. For example, action 1 means that a 20-byte character
string is written into the area pointed to by the second argument,
the pointer.
Now suppose you call
xyz
using the MODULE routine but indicating in the attribute
table that the receiving character argument is only 10 characters
long:
routine xyz minarg=2 maxarg=2;
arg 1 input num byvalue format=ib4.;
arg 2 output char format=$char10.;
Regardless of the
value given by the LENGTH statement for the second argument to MODULE,
MODULE passes a pointer to a 10-byte area to the
xyz
routine. If
xyz
writes 20 bytes at that
location, the 10 bytes of memory following the string provided by
MODULE are overwritten, causing unpredictable results:
data _null_;
length x $20;
call module('xyz',1,x);
run;
The call might work fine, depending on which
10 bytes were overwritten. However, this action might also cause
you to lose data or cause your system to crash.
Also, note that the
PEEKLONG and PEEKCLONG functions rely on the validity of the pointers
that you supply. If the pointers are invalid, it is possible that
SAS could crash. For example, this code would cause a crash:
data _null_;
length c $10;
/* trying to copy from address 0!!!*/
c = peekclong(0,10);
run;
Ensure that your pointers
are valid when using PEEKLONG and PEEKCLONG.