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