The MODULE function
relies 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 that is pointed to by the second argument,
the pointer.
Suppose you call
xyz
using the MODULE function, but you indicate 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, overwriting can 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
severe errors will result. For example, this code causes an error:
data _null_;
length c $10;
/* trying to copy from address 0!!!*/
c = peekclong(0,10);
run;