home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12549 < prev    next >
Encoding:
Text File  |  1992-08-19  |  1.2 KB  |  33 lines

  1. Path: sparky!uunet!mdcbbs!mdcbbs.com!mackintosh
  2. Newsgroups: comp.lang.c
  3. Subject: Re: malloc causes a segmentation violation!?
  4. Message-ID: <1992Aug19.175942.2510@mdcbbs.com>
  5. From: mackintosh@mdcbbs.com (Alasdair Mackintosh)
  6. Date: 19 Aug 92 17:59:41 PDT
  7. References: <1992Aug18.143135.6259@cc.tut.fi>
  8. Distribution: world
  9. Organization: M&E (Division of EDS), Cypress CA
  10. Nntp-Posting-Host: devhpp4
  11. Lines: 20
  12.  
  13. In article <1992Aug18.143135.6259@cc.tut.fi>, mn87504@cs.tut.fi (Naatula Mika) writes:
  14.  
  15. |> My program uses a lot of dynamic memory allocation, but I am quite
  16. |> sure that there is no bugs in my code. I have spent two days checking
  17. |> out the memory allocation of this program.
  18.  
  19.     You might want to look for code along the lines of:
  20.  
  21.         char *new_string = malloc( strlen( old_string ) );
  22.  
  23.     This should, of course, be:
  24.  
  25.         char *new_string = malloc( strlen( old_string ) +1 );
  26. -- 
  27. ===============================================================================
  28. Alasdair Mackintosh                             mackintosh@vxd.mdcbbs.com
  29. Unigraphics Division                            (714) 952-5698
  30. Electronic Data Systems                         10824 Hope St, Cypress CA
  31.  
  32.  
  33.