home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.coherent
- Path: sparky!uunet!utcsri!torn!maccs!mcshub!csx.cciw.ca!hcp
- From: hcp@csx.cciw.ca (H.C. Pulley)
- Subject: Re: Bug in Coherent 4.0 Compiler
- Organization: Canada Centre for Inland Waters
- Distribution: usa
- Date: Mon, 17 Aug 1992 19:19:25 GMT
- Message-ID: <1992Aug17.191925.3122@csx.cciw.ca>
- References: <1992Aug17.133350.7012@miles.com> <SJE.92Aug17114818@xylos.ma30.bull.com>
- Lines: 47
-
- In article <SJE.92Aug17114818@xylos.ma30.bull.com> sje@xylos.ma30.bull.com writes:
- >> -------------------------------------- cut here ------------------------
- >> char *string = "Hello World\n";
- >>
- >> main()
- >> {
- >> char **pp;
- >>
- >> *pp = string;
- >> printf("%s", *pp);
- >> }
- >> -------------------------------------- and here ------------------------
- >>
- >> This program bombs my system and dumps the core. I have tried this
- >> on other UNIX systems and even dos and it works just fine...
-
- Check again. Under EP/IX here the program does not dump core but no message
- is printed. Under ULTRIX, the program causes a Segmentation Violation and
- dumps a big core.
-
- >> How can this get corrected? Do we have to wait until 4.1????
- >
- >It's a bug in your code. The value of variable pp is undefined at the
- >time it is dereferenced in the statement "*pp = string". That
- >assignment is either trashing four bytes somewhere or trying to write
- >outside the data segment. It is not a problem with Coherent.
-
- Since DOS doesn't use any memory protection, this problem will only show up
- if pp points to something crucial. I still doubt, however, that the message
- will be printed correctly, since *pp is not pointing to the right place.
-
- Your problem lies with *string being a 'pointer to char' and **pp being a
- 'pointer to pointer to char'. The line
- *pp=string
- is attempting to set the area of memory pointed to by pp to the value string,
- which is a memory location. Since pp is uninitialized, as pointed out by
- Steve, you may trash memory by assigning it a value.
-
- I don't want to sound insulting here, but that is the wierdest 'Hello, World'
- program I have ever seen.
-
- Harry
- --
- hcp@csx.cciw.ca | This message | It takes all kinds,
- hcpiv@grumpy.cis.uoguelph.ca | released to the | and to each his own.
- -----------------------------------| PUBLIC DOMAIN. | This thought in mind,
- Stay away from the DOS side Luke! | | I walk alone.
-