cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Problem with binary data

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 31 Oct 2003 21:55:32 +0100 (CET)

On Fri, 31 Oct 2003, Sharma, Amit wrote:

Let me first second what others have said before in this thread:

* HTTP sends binary data perfectly
* libcurl receives binary perfectly
* libcurl sends binary perfectly to the callback of yours

> FILE* fd=fopen("ImageFile.txt","r");
> if(!fd)
> {
> /* Log error. */
> }
> char *cptrServerResponse = new char [BUFF];
> int NumberOfBytesForImages=fread(cptrServerResponse,
> sizeof(char),BUFF_SWAP,fd);
> cout<<endl<<"Number of bytes read "<<NumberOfBytesForImages;
> cptrServerResponse[NumberOfBytesForImages]='\0';
> fclose(fd);
> }
>
> /* This function strips off the first 11 bytes tag "|DELIMITER|" */
> int ProcessXmlStat = ProcessServerResponse(cptrServerResponse);

1. The ProcessServerResponse() function is called with a variable pointer that
   was declared in another context and that shouldn't exist there.

2. Why does the code zero-terminate the read data? It seems to indicate that
   you have code that assumes zero could be the end of the received data.

3. Passing in binary data using a single 'char *' to a function seems odd,
   how's that function supposed to know what size the data is?

> It just struck my mind. Could there be a problem because am trying to read
> from the file in a character array which actually truncates one of the bytes
> thus corrupting the data.

If you would tell us more details on HOW the corruption looks, we might be
able to offer even more clues.

-- 
 Daniel Stenberg -- curl: been grokking URLs since 1998
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
Received on 2003-10-31