Random Chitchat 2012-2016
And how can i do it then?
Thanks given by:
Fix this line
Code:
int UncompressedMaxSize = DataLength - (DataLength << 12) - (DataLength << 14) - (DataLength << 25) - 16;
It's probably wrong. Check the value you get from it.
Thanks given by:
(07-13-2014, 12:39 AM)FakeTruth Wrote: Fix this line
Code:
int UncompressedMaxSize = DataLength - (DataLength << 12) - (DataLength << 14) - (DataLength << 25) - 16;
It's probably wrong. Check the value you get from it.

It's the opposite of the compress code.
I use now 1000000 for testing.
Code:
char Output [1000000];
int success = uncompress((Bytef *)Output, (uLongf *)1000000, (const Bytef *)ChunkData.c_str(), (uLong)DataLength);
But then the uncompress crashes. Shouldn't i use c_str() or so?
Thanks given by:
(07-13-2014, 01:27 AM)daniel0916 Wrote:
(07-13-2014, 12:39 AM)FakeTruth Wrote: Fix this line
Code:
int UncompressedMaxSize = DataLength - (DataLength << 12) - (DataLength << 14) - (DataLength << 25) - 16;
It's probably wrong. Check the value you get from it.

It's the opposite of the compress code.
I use now 1000000 for testing.
Code:
char Output [1000000];
int success = uncompress((Bytef *)Output, (uLongf *)1000000, (const Bytef *)ChunkData.c_str(), (uLong)DataLength);
But then the uncompress crashes. Shouldn't i use c_str() or so?

I don't know. I don't know what ChunkData is, or what DataLength is, or what it holds.

You should definitely focus on this line though:
Code:
int UncompressedMaxSize = DataLength - (DataLength << 12) - (DataLength << 14) - (DataLength << 25) - 16;

I'm telling you, check the resulting value of that calculation, it's probably not what you expect. I expect a negative number.
Do you know what << means?
Thanks given by: daniel0916
(07-13-2014, 01:27 AM)daniel0916 Wrote: I use now 1000000 for testing.
Code:
char Output [1000000];
int success = uncompress((Bytef *)Output, (uLongf *)1000000, (const Bytef *)ChunkData.c_str(), (uLong)DataLength);
But then the uncompress crashes. Shouldn't i use c_str() or so?

Of course it crashes. The second parameter is all wrong. The function expects a pointer to memory where the buffer's length is stored, and it writes to that memory the actual number of bytes written. You're forcing a number down its throat instead of a pointer, so it tries to access memory at address 1000000. Most likely that address is not available for the program, so it crashes; but even if it didn't crash, it wouldn't work well for you.

You need to do this:
char Output [1000000];
uLongf BufferSize = sizeof(Output);
int success = uncompress((Bytef *)Output, &BufferSize, (const Bytef *)ChunkData.data(), (uLong)DataLength);
// BufferSize now contains the number of bytes actually uncompressed
Thanks given by: daniel0916
Xoft, is that not a pointer to the length of the buffer, not the buffer itself?
Thanks given by:
(07-13-2014, 05:46 PM)bearbin Wrote: Xoft, is that not a pointer to the length of the buffer, not the buffer itself?

That's what he's sayingBig Grin
Thanks given by:
Slightly edited to make it more comprehensible Smile
Thanks given by:
Okay, thanks.
Code:
char Output [1000000];
    uLongf BufferSize = sizeof(Output);
    int success = uncompress((Bytef *)Output, &BufferSize, (const Bytef *)ChunkData.data(), (uLong)DataLength);
    
    if (success != Z_OK)
    {
        return false;
    }
    
    if (!Packet.Write((const char *)Output, (size_t)BufferSize))
    {
        return false;
    }

Is this code right? Because the client disconnects because it's too big. I think i need to define on the Write method the writed size not the full size or?
Thanks given by:
The client expects compressed data, so it will disconnect if you write uncompressed data to it.
Thanks given by:




Users browsing this thread: 31 Guest(s)