home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!ames!sgi!quasar.wpd.sgi.com!davea
- From: davea@quasar.wpd.sgi.com (David B.Anderson)
- Newsgroups: comp.sys.sgi
- Subject: Re: Possible bug in c-compiler ?
- Message-ID: <oj35voc@sgi.sgi.com>
- Date: 15 Aug 92 00:42:38 GMT
- Sender: davea@quasar.wpd.sgi.com
- Organization: Silicon Graphics, Inc. Mountain View, CA
- Lines: 48
-
- In article <1992Aug14.165251.20524@sni.ca> ash@sni.ca (Ashwin Palekar) writes:
- >ON: IRIX 4.0.1 11150233 IP12
- >
- >Problem Description:
- >~~~~~~~~~~~~~~~~~~~~
- > The software works with debug version (default compiler option)
- >and dumps core in optimised version (-O).
- >
- >Problem Analysis :
- >~~~~~~~~~~~~~~~~~
- > the code has the following logic.
- >{
- > struct xyz *variable=NULL;
- > setjmp();
- >
- > variable = ... allocate memory.
- > free (variable)
- > variable = NULL;
- >
- > longjmp(Go to statement shown next)
- >
- > if variable != NULL free(variable)
- >
- >}
- >
- >In debug mode "variable" is equal to NULL after longjmp.
- >In optimised mode "variable" it is not NULL after longjmp tries to free it
- >resulting in core dump.
- >
- >IMP: This same behaviour is noticed on mips platform (maybe because of
- >same compiler).
-
- The compiler is not broken. Your code is making an unwarranted assumption.
-
- Loosely speaking: You want to declare any variable that he is altered
- in a function doing setjmp volatile. Example:
-
- struct xyz * volatile variable = NULL;
-
- In the absence of "volatile" the compiler is free to do optimizations
- that will break your code.
-
- Possible starting points for RTFM-ing:
- ANSI C Std section 4.6.1 and 4.6.2,
- ISO C Std 7.6.1 7.6.2
- K&R2, section B8, page 254.
-
- [ David B. Anderson (415)390-1548 davea@sgi.com ]
-