cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: cURL bug -- Segmentation Fault when timeout is 1 second

From: Gary Maxwell <gmaxwell_at_casabi.com>
Date: Wed, 4 Feb 2009 10:01:44 -0800

Daniel Marschall on February 04, 2009 9:49 AM wrote:
>
> But there are 2 problems I still have:
>
> 1. I want to have an infinite big buffer, like a std::string in C++.
If
> the
> website-output is larger than the buffer size, then I get a
> memory-access-error again.
>
> Isn't "char*" an infinite c-string that waits for an 0x0 termination
> sequence, is it?

"char*" is certainly NOT an infinite c-string. It is simply a pointer
to an area of memory that contains sequential characters, the
size of which you determine when you statically define or dynamically
allocate the memory.

You can easily expand the size of your buffer in the write callback
function. Look at the documentation for realloc().

>
> 2. The output of the buffer with printf() is not correct. Some foreign
> memory contents are in my string... The output is like:
>

Whoever said that the response from the server would be printable
UTF-8 data? The server will send back whatever data it thinks you asked
for, be it text, images, or sound bites. This is what particularly
alarmed me in your earlier example code, using strncpy() in the write
callback. You should instead use memcpy().

-GaryM at casabi
Received on 2009-02-04