home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / programm / 3919 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  1.1 KB

  1. Path: sparky!uunet!auspex-gw!guy
  2. From: guy@Auspex.COM (Guy Harris)
  3. Newsgroups: comp.unix.programmer
  4. Subject: Re: I am stumped on this one!!!
  5. Message-ID: <13744@auspex-gw.auspex.com>
  6. Date: 26 Jul 92 02:14:54 GMT
  7. References: <1992Jul24.204944.18516@cbfsb.cb.att.com> <Brx394.4qL@undergrad.math.waterloo.edu>
  8. Sender: news@auspex-gw.auspex.com
  9. Organization: Auspex Systems, Santa Clara
  10. Lines: 18
  11. Nntp-Posting-Host: auspex.auspex.com
  12.  
  13. >>        cp_line = (char *)malloc(sizeof(strlen(pars_wbuf)));
  14. >
  15. > You're allocing the sizeof an int, which is likely four bytes.
  16. > You also forgot to alloc space for the '\0'. Try it again with:
  17. >
  18. >    cp_line = (char*)malloc(sizeof(strlen(pars_wbuf) + 1));
  19.  
  20. No, try it again with:
  21.  
  22. >    cp_line = (char*)malloc(strlen(pars_wbuf) + 1);
  23.  
  24. because, as you noted, the "sizeof" doesn't belong there - it turns the
  25. argument into the size of the result of "strlen", which isn't the length
  26. of the string.
  27.  
  28. (Also, try not leaving every single line of the original posting in your
  29. followup; it makes it rather hard to find the stuff that *doesn't* come
  30. from the original posting....)
  31.