home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / amiga / programm / 15645 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.5 KB  |  44 lines

  1. Path: sparky!uunet!gumby!destroyer!cs.ubc.ca!keats.rick.cs.ubc.ca!not-for-mail
  2. From: c1a192@rick.cs.ubc.ca (Oliver Erik Seiler)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: What is wrong with this very simple c program?
  5. Date: 10 Nov 1992 14:19:03 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Lines: 32
  8. Message-ID: <1dpcgnINNf88@keats.rick.cs.ubc.ca>
  9. References: <1992Nov10.184406.25907@sol.UVic.CA>
  10. NNTP-Posting-Host: keats.rick.cs.ubc.ca
  11.  
  12.  
  13. aramsey@ugly.UVic.CA (Aaron  Ramsey) coded this thingy:
  14. >#include <stdio.h>
  15. >
  16. >main()
  17. >{
  18. >   int zoop[1000];
  19.              ^^^^
  20. >      int counter;
  21. >
  22. >            printf ("started....");
  23. >               for (counter = 0; counter < 5000; counter += 5) {
  24.                         ^^^^
  25. >                     zoop[counter] = counter;
  26. >                        }
  27. >                           printf("done....");
  28. >                           }
  29.  
  30. Well you are writing to locations past the bounds of the array. Since the
  31. array is local, it is on the stack. SO you are overwriting values on the
  32. stack (since the stack is organized backwards in memory)... ie. You are
  33. killing the return addresses which are placed on the stack. Therefore you guru
  34.  
  35. Change the size of the array, or the bounds of the 'for' loop...
  36.  
  37. -Oliver
  38.  
  39. -- 
  40. \  Oliver Seiler  /\  \    /  /      _                              |||||
  41.  \               /  \  \  /  /      /o\__   <--- My dream car...    (o o)
  42.   \             /    \  \/  /_______-O--O'_____                      \^
  43.    \_Insomniak_/      \_c1a192@rick.cs.ubc.ca_/                     _| |_
  44.