Unix Programming - Re: Segmentation fault when writing to a file once it has reacher

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > October 2006 > Re: Segmentation fault when writing to a file once it has reacher





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Segmentation fault when writing to a file once it has reacher
T.M. Sommers

2006-10-25, 7:18 am

Wes wrote:
> On Thu, 19 Oct 2006 13:24:22 -0400, "T.M. Sommers" <tms@nj.net> wrote:
>
> How do you mean? If I use constant strings I won't be able to change
> them will I?


I meant the numbers specifying the sizes of the arrays. It is
better to do something like:

const int ARRAY_SIZE = 32;

if you absolutely have to use an array. But usually you should
be using std::string.

> Also, some of the functions I'm using require char*s
> (most importantly, read and write).


If you need a fixed-size buffer, then an array might be appropriate.

>
> Originally, the line was "enc.write(Encrypt(buffer), 32);", giving
> write() its pointer directly from the Encrypt function. However, the
> problem still existed. Does that still leak memory? If so, how should
> I rewrite that portion to not leak memory?


It could leak, depending on how it is implemented. How to fix it
will also depend on the implementation.

>
> How do you mean? What is 'gcount'?


istream::gcount() returns the number of characters read in the
last unformatted read operation.

--
Thomas M. Sommers -- tms@nj.net -- AB2SB

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com