c - Why My DeCompression is showing an Error? -
the code provided here , runing , showing errors - http://ideone.com/gweoiv
#include <stdio.h> #include <stdlib.h> unsigned char *mycompress(unsigned int num, unsigned char *buffer); unsigned int mydecompress(unsigned char **buffer); int main(void) { unsigned char *abc, *abc2; unsigned len; abc=(unsigned char *)malloc(12); abc2=abc; len=25960; abc = mycompress(len, abc); len=385; abc = mycompress(len, abc); len=900; abc = mycompress(len, abc); len=20560; abc = mycompress(len, abc); len=384; abc = mycompress(len, abc); abc=abc2; len = mydecompress(&abc); len = mydecompress(&abc); len = mydecompress(&abc); len = mydecompress(&abc); len = mydecompress(&abc); homecoming 0; } unsigned int mydecompress(unsigned char **buffer){ unsigned int c; unsigned int num = 0; unsigned char *p = *buffer; printf("\n\ndecompression\n===============\n"); do{ c = ((unsigned char) *p++); printf("read=%d\n", c); if (c <= 0) { printf("error: c < 0 in uncompress1()\n"); exit(0); } num <<= 7; num |= c & 127; printf("uncompress: c = %d num = %d\n", c, num); if (!num) break; }while (c & 128); *buffer = p; printf("returning %d\n", num); homecoming num; } unsigned char *mycompress(unsigned int num, unsigned char *buffer){ int = 0; unsigned int r = num; unsigned char temp; unsigned char s[5]; printf("compression\n===============\n"); printf("received %d compress\n", num); if(!r){ *buffer++ = 0; homecoming buffer; } while (r){ s[i] = r & 127; r >>= 7; printf("s[%d]=%d; r=%d\n", i, s[i], r); i++; } while (--i >= 0){ temp = (unsigned char)(s[i] | (i ? 128 : 0)); printf("temp=%d\n", temp); *buffer++=temp; } homecoming buffer; }
//output:
compression =============== received 25960 compress s[0]=104; r=202 s[1]=74; r=1 s[2]=1; r=0 temp=129 temp=202 temp=104 compression =============== received 385 compress s[0]=1; r=3 s[1]=3; r=0 temp=131 temp=1 compression =============== received 900 compress s[0]=4; r=7 s[1]=7; r=0 temp=135 temp=4 compression =============== received 20560 compress s[0]=80; r=160 s[1]=32; r=1 s[2]=1; r=0 temp=129 temp=160 temp=80 compression =============== received 384 compress s[0]=0; r=3 s[1]=3; r=0 temp=131 temp=0 decompression =============== read=129 uncompress: c = 129 num = 1 read=202 uncompress: c = 202 num = 202 read=104 uncompress: c = 104 num = 25960 returning 25960 decompression =============== read=131 uncompress: c = 131 num = 3 read=1 uncompress: c = 1 num = 385 returning 385 decompression =============== read=135 uncompress: c = 135 num = 7 read=4 uncompress: c = 4 num = 900 returning 900 decompression =============== read=129 uncompress: c = 129 num = 1 read=160 uncompress: c = 160 num = 160 read=80 uncompress: c = 80 num = 20560 returning 20560 decompression =============== read=131 uncompress: c = 131 num = 3 read=0 error: c < 0 in uncompress1()
why getting error: when decompress 384 number?
you asked question, , answered here. 0 expected byte in coding scheme, , must not rejected. delete if (c <= 0)
section.
c compression decompression
No comments:
Post a Comment