home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: alt.folklore.computers
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!hellgate.utah.edu!fcom.cc.utah.edu!lanai!bcc
- From: bcc@lanai.Eyring.COM (Brian Cooper)
- Subject: Re: Computer Superstition
- Message-ID: <1992Nov20.015335.19860@fcom.cc.utah.edu>
- Sender: news@fcom.cc.utah.edu
- Organization: University of Utah Computer Center
- References: <10292323.7317.11306@kcbbs.gen.nz> <1992Nov18.124517@frej.teknikum.uu.se>
- Date: Fri, 20 Nov 92 01:53:35 GMT
- Lines: 52
-
- In article <1992Nov18.124517@frej.teknikum.uu.se> flax@mizar.docs.uu.se writes:
- >In article <10292323.7317.11306@kcbbs.gen.nz>, Murray_Moffatt@kcbbs.gen.nz (Murray Moffatt) writes:
- >|> We've all heard of common superstitions such as not walking under ladders
- >|> and throwing salt over your left shoulder if you spill some, but are
- >|> there any superstitions to do with computers?
- >|>
- >Er, well, yes.. We no longer use Apollo around here, but there was a known
- >bug with the 'system' library call. Under certain circumstances it
- >thrashed the stack, including the return address.
- >Easy fix to this was to pad the stack by declaring an character array of
- >size 12 or 16 (3-4 longwords would do it) to protect the return address.
- >I found this out while debugging some assembler code, and when a friend was
- >writing code along the lines of
- >int foobar(char *str)
- >{
- >/* stuff */
- >return system(str);
- >}
- >things just wouldn't work out..
- >
- >I asked him to rewrite the code as:
- >
- >int foobar(char *str)
- >{
- > char magic[12];
- > /* stuff */
- > return system(str);
- >}
- >
- >and things would work, proving that you can't take magic out of
- >your program.. :-)
- >
- >Several years after that I still see people add magic to programs
- >using 'system', not knowing why, but stating that it can't hurt.. :-)
- >
-
- Ah, but sometimes the magic goes away! I was writing a program where I
- deliberately used this technique to increase the stack space between
- recursive invocations and it wouldn't work. Come to find out, two
- different compilers for two different systems optimized my code by
- removing the dummy array. Quietly, without any fanfare, the compiler
- altered the meaning of my code. Logic dictates that if the variable is
- never referenced, it must not need to be there, right!? I included a
- stupid reference to the dummy variable and the program worked. I recommend
-
- char magic[12];
- magic[0] = magic[1];
-
- for modern wizards.
- --
- Brian Cooper bcc@Eyring.COM
- Eyring Corp. +1 801-375-2434 or 1 800 YES PDOS
-