[5581] in Athena Bugs

home help back first fref pref prev next nref lref last post

Re: rt 6.4R: MATLAB, crash in sprintf routine

daemon@ATHENA.MIT.EDU (sethf@ATHENA.MIT.EDU)
Thu Jul 19 21:16:57 1990

From: sethf@ATHENA.MIT.EDU
Date: Thu, 19 Jul 90 21:16:45 -0400
To: jik@ATHENA.MIT.EDU
Cc: bugs@ATHENA.MIT.EDU, sethf@ATHENA.MIT.EDU
In-Reply-To: bugs[5548]

>>   What were you trying to do?
>>	   Determine how MATLAB's sprintf routine worked, and whether a
>>   string was a legal argument. I typed
>>		   sprintf('Foo %s','foo')
>>   What's wrong:
>>	   Segmentation violation
>>
>>   What should have happened:
>>	   A less drastic error message.

> Sorry, but I disagree.  You told matlab to write into a constant
> string, probably overwriting the memory reserved for that string.
> There is no way for it to check that, and in fact, the same thing
> would result if you did the same thing in a C program with the C
> sprintf() function.

> I consider segmentation faulting in response to what you did to fall
> quite soundly within the bounds of "wreaking havoc."  They documented
> the function that way *because* they know that it's not possible to
> check for things such as what you did.

	Sorry, I disagree with the disagreement :-). Your reply seems to
me to be based on a confusion between the forms of the C and MATLAB
sprintf. The C sprintf has the usage sprintf(buf, format, args), while
MATLAB's sprintf takes the form sprintf(format, args), with buf being
internal. That MATLAB statement is not equivalent to identical C
statement (which would indeed be erroneous), but rather to the C
sprintf(buf,"Foo %s","foo"), which is perfectly legal (buf being
previously properly declared). Or at least so my thoughts ran.
	What are interpreters for, if not to check possibly
dangerous errors?  I don't think what I typed was unreasonably odd or
unpredictable. In this context, I thought "wreak havoc" meant produce
an utter garbage string, not crash the entire program.

================
Seth Finkelstein
sethf@athena.mit.edu

home help back first fref pref prev next nref lref last post