home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / folklore / computer / 16466 < prev    next >
Encoding:
Text File  |  1992-11-19  |  2.4 KB  |  64 lines

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