[metapost] Bugs in mpost 1.202 (and less)?

Taco Hoekwater taco at elvenkind.com
Sat Jun 6 11:53:02 CEST 2009


Nicola wrote:
> Hi,
> I have stumbled on a couple of potential bugs (mpost compiled for Intel 
> Mac OS X with gcc 4.0.1):

I can confirm both bugs.

> 1) the following code:
> 
> vardef foo@# = @ enddef; foo.a;
> 
> causes a segmentation fault with mpost 1.201 and 1.202, while it 
> correctly generates a stack capacity exceeded error in mpost 1.005.

It depends at least a little bit on how one defines 'correctly'. The
crash in 1.20x happens because the C call stack is exhausted. The
error in 1.005 was because there was an artificial limit imposed by
the pascal source code. You got the 'correct' error message in 1.005
only because on your machine the artificial limit was hit earlier in
time than the C call stack exhaustion.

The problem is that a program can't reliably discover when the C call
stack will be exhausted (at least not until after it has already
happened, and even then error handling is fairly hard to do in a
portable fashion).

I'll think about this some more, but a proper bug fix will not be
happening soon, I fear. Meanwhile, please do not program endless
loops on purpose ;)


> 2) This program:
> 
> warningcheck:=0;
> n = 32767; % or whatever number
> for i = n upto 32767: endfor;
> end.
> 
> seems to loop forever (tested on 1.005 and 1.202).

The endless loop is an artifact of 32-bit integer wrapping, where
32767+1 == -32767. Because of this, it loops endlessly through all the
values from -32767 upto 32767.

This problem should automatically go away with the next major metapost
release, when the internal calculations will be replaced by an arbitrary
precision library.

Thanks for the reports,
Taco




More information about the metapost mailing list