Qt qUncompress giving "could not allocate enough memory to uncompress data" -


i have following code failing when called error:

quncompress: not allocate enough memory uncompress data 

code:

qstring decstage3 ( qbytearray s ) {     printf ( "3a: length in %d\n", s.length());     qbytearray bdata = qbytearray::fromhex(s );     printf ( "3b: length ba %d\n", bdata.length());     printf ( "3c: ba [%s]\n", qprintable(bdata.tohex()));     printf ( "3d: mem [%d]\n", bdata.capacity() );      qbytearray ds = quncompress( bdata );    // qbytearray::fromhex(s.tolatin1());     return (ds.data()); } 

example input "789c0b492d2e5170492c490400101e033b" ( == "test data" ).

update: following chernobyl's suggestion, decided add direct test follows:

void tst ( qbytearray b0 ) {     qbytearray b1 = qcompress (b0);     printf ( "[%s] %d = [%s] %d\n", qprintable(b0), b0.length(), qprintable(b1.tohex()), b1.length());     qbytearray b2 = quncompress (b1);     printf ( "uncomp = [%s]\n", qprintable(b2)); } 

then tested:

tst ("hello"); tst ("hello world"); tst ("hello world nice see you"); 

this gave following:

[hello] 5 = [00000005789cf348cdc9c90700058c01f5] 17 uncomp = [hello] [hello world] 11 = [0000000b789cf348cdc9c95708cf2fca490100180b041d] 23 uncomp = [hello world] [hello world nice see you] 27 = [0000001b789cf348cdc9c95708cf2fca4951f0cb4c4e5508c957084e4d5588cc2f050082f70939] 39 uncomp = [hello world nice see you] 

notice first 8 bytes appear hold length (hex) of original string. haven't come across behaviour before. can amend source program include (from system, in java), there way avoid having this?

fixed (or rather got working) preprending dummy length before zip data (starting 789c):

qstring decstage3 ( qbytearray s ) {     printf ( "3a: length in %d\n", s.length());     qbytearray bdata = qbytearray::fromhex("00004000") + qbytearray::fromhex(s );     printf ( "3b: length ba %d\n", bdata.length());     printf ( "3c: ba [%s]\n", qprintable(bdata.tohex()));     printf ( "3d: mem [%d]\n", bdata.capacity() );      qbytearray ds = quncompress( bdata );    // qbytearray::fromhex(s.tolatin1());     return (ds.data()); } 

it's line declare bdata, prepending "00004000". evaluates 16k. turns out although on compress denotes length of uncompressed data, on uncompess doesn't need accurate length. so, assuming more memory grab used internally uncompress, opted 16k more enough data expect.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -