home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11460 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  1.7 KB

  1. Path: sparky!uunet!mcsun!fuug!demos!kiae!glas!demos!curie.ces.cwru.edu!glenn
  2. From: glenn@curie.ces.cwru.edu
  3. Newsgroups: comp.lang.c
  4. Date: 17 Jul 92 10:46 MDT
  5. Subject: Array bounds checking
  6. Sender: Notesfile to Usenet Gateway <notes@glas.apc.org>
  7. Message-ID: <GLENN.92Jul17104644@curie.ces.cw>
  8. Nf-ID: #N:GLENN.92Jul17104644@curie.ces.cw:1802369180:001:1316
  9. Nf-From: curie.ces.cwru.edu!glenn    Jul 17 10:46:00 1992
  10. Lines: 51
  11.  
  12.  
  13.  
  14. Hey there.  I've inherited a pathetic piece of "software", chock full
  15. o' things like
  16.  
  17. foo = (char *) malloc (strlen (bar));
  18. strcpy (foo, bar);
  19.  
  20. I've got 4 or 5 malloc debugging systems, so most problems like the
  21. above are solved now, but I'm trying to figure out a way to check for
  22. things like this:
  23.  
  24. void foo(void)
  25. {
  26.     int local[5];
  27.  
  28.     local[5] = 3;
  29. }
  30.  
  31. Sure, I can change these to something like this:
  32.  
  33. void foo(void)
  34. {
  35.     int *local;
  36.  
  37.     local = (int *) malloc (sizeof (int) * 5);
  38.     local[5] = 3;
  39.     free (local);
  40. }
  41.  
  42. (which my picky malloc debuggers will point out to me.)
  43.  
  44. But this sucks.  When I'm not debugging, I'd really like that array of
  45. ints to be on the stack.
  46.  
  47. Any suggestions about systems that might do something like this?  I
  48. know about CodeCenter (formerly Saber) C, which will do this in its
  49. sleep, but it's quite costly, and I'd like to either find or write
  50. something GNUish.
  51.  
  52. If there's nothing out there, I'd appreciate suggestions on how best
  53. to do this.  What I'm thinking about currently is an option to GCC
  54. like -fruntime-bounds-check.  If anyone's given this some thought, I'd
  55. love to hear about it.
  56.  
  57. --
  58. Glenn Crocker                   |  Hackers aren't unethical, they're
  59. glenn@ces.cwru.edu              |  "Differently-ethical."
  60. CWRU, Cleveland, OH             |
  61. W (216)368-6133 H (216)791-4610 |
  62.  
  63.