Subject: Re: Which Scheme are you using?
From: (Rob Warnock)
Date: 1998/06/04
Newsgroups: comp.lang.scheme
Message-ID: <6l5o1i$>

Peter Murray <> wrote:
| >|      (printf "%s")
| >| Just crashing is not acceptable.
| >+---------------
| >
| >Gee, I don't know why not??!?  ;-}  ;-}
| >It "just crashes" when you do that in C, too!
| You actually got that to compile in C??!? 


Well, o.k., it helps to fool it a bit by passing the format string as an
arg instead of a literal string, since some C compilers are smart enough
to compare literal format strings with the args to a "printf". But in a
Scheme-to-libc FFI the C compiler would never see the literal source strings
either (they'd be passed as args from the Scheme program), so I think this
is fair.

And you may also need to have done a recent call with a bad address where
the nonexistent second arg should be, otherwise it might not actually "crash",
just print garbage (which is all my first attempt did).

But given those disclaimers, yes, it compiled. And crashed.

	% cat crash.c
	void foo(char *s) { printf(s); }

	/* dummy routine to let us leave trash in the arg#2 location */
	void bar(int x, int y) { return; }

	void main()
	{ bar(1,2);	/* "2" is a bad address on this system */
	  foo("%s"); }

	% cc -ansi -O -o crash crash.c

	% crash
	Segmentation fault (core dumped)


Rob Warnock, 7L-551
Silicon Graphics, Inc.		Phone: 650-933-1673
2011 N. Shoreline Blvd.		FAX: 650-933-4392
Mountain View, CA  94043	PP-ASEL-IA