home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / programm / 3979 < prev    next >
Encoding:
Text File  |  1992-07-28  |  2.2 KB  |  58 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!psinntp!spike.insci.com!augie!ross
  3. From: ross@augie.insci.com (ross andrus)
  4. Subject: Re: I am stumped by this one!!!
  5. Organization: Insci Incorporated
  6. Distribution: usa
  7. Date: Tue, 28 Jul 1992 18:52:59 GMT
  8. Message-ID: <1992Jul28.185259.2571@spike.insci.com>
  9. References: <Brx394.4qL@undergrad.math.waterloo.edu> <13744@auspex-gw.auspex.com> <1992Jul27.134826.5592@cbfsb.cb.att.com>
  10. Sender: news@spike.insci.com (News spooler)
  11. Lines: 45
  12.  
  13. In article <1992Jul27.134826.5592@cbfsb.cb.att.com> rajeev@cbnewsf.cb.att.com (rajeev.dolas) writes:
  14. >In article <13744@auspex-gw.auspex.com> guy@Auspex.COM (Guy Harris) writes:
  15. >>>>        cp_line = (char *)malloc(sizeof(strlen(pars_wbuf)));
  16. >>>
  17.  
  18.   // stuff deleted
  19.  
  20. >>No, try it again with:
  21. >>
  22. >>>    cp_line = (char*)malloc(strlen(pars_wbuf) + 1);
  23. >>
  24.  
  25.   // stuff deleted
  26.  
  27. >
  28. >    I realize the error on sizeof instead of strlen() for malloc. But
  29. >    I don't think that is the cause of SEGV error. If you look at my
  30. >    original posting, you will notice that I am able to copy selected
  31. >    characters to cp_line.
  32.  
  33.   Have you actually changed the code as Guy suggested and tried it? If not,
  34.   you're only allocating sizeof(int) bytes for cp_line. If you ever try to
  35.   put more than that many bytes there, you are almost guaranteed to hose
  36.   your storage arena. After which the only thing between you and a core 
  37.   file is time and execution flow - i.e. luck.
  38.  
  39. >    In my original code I wasn't even using the cp_line. I was reading
  40. >    a char pointed to by *pbuf and was writing that to the file. I
  41. >    got the SEGV error on the putc()!!! Now I am using fputs() to
  42. >    write a string instead of a char and I get the same error on
  43. >    fputs(). Also fputs(tmp_line,stdout) works fine while 
  44. >    fputs(tmp_line,fp1) does not!!! That's what is driving me nuts.
  45.  
  46.   Hmm. You might comb the rest of your code for stepping-on-memory problems 
  47.   similar to the above. What you've described certainly - has that feel to it. 
  48.   I would probably not conclude that the library was busted.
  49.  
  50.   Good luck
  51.  
  52.   ross
  53. -- 
  54. +-----------------------------------------------------------------------------+
  55. |  Ross Andrus  == ross@insci.com                          |
  56. |  Clever Disclaimer.                                  |
  57. +-----------------------------------------------------------------------------+
  58.