home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19561 < prev    next >
Encoding:
Text File  |  1993-01-11  |  1.1 KB  |  32 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!hobbes!md
  3. From: md@sco.COM (Michael Davidson)
  4. Subject: Re: use of REALLOC under UNIX system
  5. Organization: The Santa Cruz Operation, Inc.
  6. Date: Mon, 11 Jan 1993 22:16:07 GMT
  7. Message-ID: <1993Jan11.221607.9595@sco.com>
  8. References: <C0pC48.G2z@compsci.liverpool.ac.uk>
  9. Sender: news@sco.com (News admin)
  10. Lines: 20
  11.  
  12.  
  13. scst81@csc.liv.ac.uk (Mr. I. Rowland) writes:
  14.  
  15.  
  16. >  I have a problem with some C code
  17.  
  18.    [ .... ]
  19. >  However when I run this, at the first occurence of the REALLOC function
  20. >  clast_str = realloc(clast_str,bytes)     bytes = length of name + 1
  21. >                                           `+1' to account for `\0'
  22. >  the error `Bus error(coredump)' occurs.
  23.  
  24. The problem is that clast_str is uninitialised on your first call
  25. to realloc() - the only valid thing that you can pass to realloc()
  26. as it's first argument is the pointer returned from a successful
  27. call to malloc(), calloc() or realloc(). In other words, you can't
  28. RE-allocate something that you have never allocated in the first place!
  29.  
  30. You were lucky that the call to strlen(clast_str) didn't dump core
  31. as well.
  32.