From: Michael Gernoth Date: Mon, 2 Feb 2009 21:53:39 +0000 (+0100) Subject: cleanup extract_lz_file X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/rsbs2/commitdiff_plain/2363a0d6a8cf44f7288e0795ff29e081ecf3a08f cleanup extract_lz_file --- diff --git a/rsb-lz.c b/rsb-lz.c index 0e86bca..c90f5df 100644 --- a/rsb-lz.c +++ b/rsb-lz.c @@ -428,7 +428,7 @@ * 59b80: 46335053 undefined */ -void fn_59788(const char *fname) +void err_exit(const char *fname) { fprintf(stderr,"%s: error extracting...\n", fname); exit(1); @@ -458,7 +458,7 @@ unsigned char fn_597c8(struct data_in_s *r6_data) r1 = r6_data->stop; if (r1 < r0) - fn_59788(__func__); + err_exit(__func__); r5 = *r0; r0++; @@ -544,7 +544,7 @@ void fn_5980c(unsigned int arg1, struct data_out_s *data_out) if (r1 > r2) { printf("r1: 0x%08x, r2: 0x%08x\n", (unsigned int)r1, (unsigned int)r2); - fn_59788(__func__); + err_exit(__func__); } *r1 = arg1 & 0xff; @@ -639,41 +639,33 @@ unsigned int crc_check_59684(unsigned char *arg1, unsigned int arg2, unsigned in return 4; } -void extract_lz_file(unsigned char *buf, unsigned char *name) +void extract_lz_file(unsigned char *inbuf, unsigned char *name) { - unsigned char *r3; - unsigned int r5; - unsigned char *r7 = NULL; /* Arg1, mem start */ - unsigned char *r10 = NULL; /* Arg2, mem end */ - unsigned char *r11 = buf; /* Arg3 */ + unsigned int len; + unsigned char *outbuf; struct data_in_s data_in; struct data_out_s data_out; - if (*((unsigned int*)r11) != LZ_MAGIC) - fn_59788(__func__); + if (*((unsigned int*)inbuf) != LZ_MAGIC) + err_exit(__func__); - r3 = r11 + 4; - r5 = *((unsigned int*)r3); - printf(", length: %d", r5); + len = *((unsigned int*)(inbuf + 4)); + printf(", length: %d", len); - if ((r7 = malloc(r5)) == NULL) { + if ((outbuf = malloc(len)) == NULL) { perror("malloc"); exit(1); } - r10 = r7 + r5; - bzero(r7, r5); - r3 = r7 + r5; - if (r3 > r10) - fn_59788(__func__); - - data_in.start = r11 + 8; - data_in.stop = r5 + r11; + bzero(outbuf, len); + + data_in.start = inbuf + 8; + data_in.stop = inbuf + len; data_in.x = 0; data_in.bit = 0x80; - data_out.pos = r7; - data_out.end = r7 + r5; + data_out.pos = outbuf; + data_out.end = outbuf + len; lz_expand(&data_in, &data_out); @@ -684,11 +676,11 @@ void extract_lz_file(unsigned char *buf, unsigned char *name) if ((ret = crc_check_59684(r7, r5, 0x46335053)) != 0) { printf("crc_check return: %d\n", ret); - fn_59788(__func__); + err_exit(__func__); } #endif - write_file((char*)name, r7, r5); + write_file((char*)name, outbuf, len); - free(r7); + free(outbuf); }