[gnu.gcc.bug] gcc 1.35 pointer bug

msir_ltd@UHURA.CC.ROCHESTER.EDU (Mark Sirota) (10/05/89)

This has already been reported to Joy Kendall and may have already been
reported through other channels, since we discovered this a few days ago.

Anyway, we are running gcc-1.35 on a Sun3 with an fpa, which is running SunOS
4.0.3.

The following program causes a segmentation fault:

main()
{
	char	*s = "foo";

	*s = 'f';
}

This one seems pretty significant.  I have a hard time the compiler managed to
compile itself, and actually runs...

-- 
Mark Sirota - University of Rochester, Rochester, NY
 Internet: msir_ltd@uhura.cc.rochester.edu
 UUCP:     {decvax,harvard,ames,rutgers}!rochester!ur-cc!msir_ltd

drh@notecnirp.Princeton.EDU (Dave Hanson) (10/06/89)

In article <8910042003.AA19615@uhura.cc.rochester.edu> msir_ltd@UHURA.CC.ROCHESTER.EDU (Mark Sirota) writes:
	This has already been reported to Joy Kendall and may have already been
	reported through other channels, since we discovered this a few days ago.
	Anyway, we are running gcc-1.35 on a Sun3 with an fpa, SunOS 4.0.3.
	
	The following program causes a segmentation fault:
	main() {
		char	*s = "foo";
		*s = 'f';
	}
	This one seems pretty significant.  I have a hard time the compiler managed to
	compile itself, and actually runs...

and it should fault; the program attempts to change a constant.
it worked in old C, but not in ANSI C...

schmidt@zola.ics.uci.edu (Doug Schmidt) (10/06/89)

In article <19949@princeton.Princeton.EDU>, drh@notecnirp (Dave Hanson) writes:
>In article <8910042003.AA19615@uhura.cc.rochester.edu> msir_ltd@UHURA.CC.ROCHESTER.EDU (Mark Sirota) writes:
>	This has already been reported to Joy Kendall and may have already been
>	reported through other channels, since we discovered this a few days ago.
>	Anyway, we are running gcc-1.35 on a Sun3 with an fpa, SunOS 4.0.3.
>	
>	The following program causes a segmentation fault:
>	main() {
>		char	*s = "foo";
>		*s = 'f';
>	}
>	This one seems pretty significant.  I have a hard time the compiler managed to
>	compile itself, and actually runs...
>
>and it should fault; the program attempts to change a constant.
>it worked in old C, but not in ANSI C...

Furthermore, if you have old C programs that depend on this behavior,
you can make gcc `do the right thing' by using the -fwritable-strings
option.

Doug
--
schmidt@ics.uci.edu (ARPA) |   Per me si va nella citta' dolente.
office: (714) 856-4043     |   Per me si va nell'eterno dolore.
                           |   Per me si va tra la perduta gente.
                           |   Lasciate ogni speranza o voi ch'entrate.