From f47a376156c9c6aa2a1e930014a0dbc7f6f3c527 Mon Sep 17 00:00:00 2001
From: fbrosson <fbrosson@localhost>
Date: Mon, 6 Feb 2017 17:31:50 +0000
Subject: gcc2


diff --git a/adc.c b/adc.c
index caa3a46..3937ec4 100644
--- a/adc.c
+++ b/adc.c
@@ -6,8 +6,6 @@
 
 int adc_decompress(int in_size, unsigned char *input, int avail_size, unsigned char *output, int *bytes_written)
 {
-	if (in_size == 0)
-		return 0;
 	bool output_full = false;
 	unsigned char *inp = input;
 	unsigned char *outp = output;
@@ -16,6 +14,9 @@ int adc_decompress(int in_size, unsigned char *input, int avail_size, unsigned c
 	int offset;
 	int i;
 
+	if (in_size == 0)
+		return 0;
+
 	while (inp - input < in_size) {
 		chunk_type = adc_chunk_type(*inp);
 		switch (chunk_type) {
diff --git a/dmg2img.c b/dmg2img.c
index 828308c..e117b71 100644
--- a/dmg2img.c
+++ b/dmg2img.c
@@ -112,6 +112,8 @@ int main(int argc, char *argv[])
 	char reserved[5] = "    ";
 	char sztype[64] = "";
 	unsigned int block_type, dw_reserved;
+	char szSignature[5];
+	int rSignature;
 
 	for (i = 1; i < argc; i++) {
 		if (!strcmp(argv[i], "-s"))
@@ -173,9 +175,8 @@ int main(int argc, char *argv[])
 		fseeko(FIN, 0, SEEK_SET);
 		read_kolyblk(FIN, &kolyblk);
 	}
-	char szSignature[5];
 	szSignature[4] = '\0';
-	int rSignature = convert_int(kolyblk.Signature);
+	rSignature = convert_int(kolyblk.Signature);
 	memcpy(szSignature, &rSignature, 4);
 
 	if (debug) {
@@ -213,6 +214,7 @@ int main(int argc, char *argv[])
 		printf("Debug info will be written to dmg2img.log\n\n");
 
 	if (kolyblk.XMLOffset != 0 && kolyblk.XMLLength != 0) {
+		char *_blkx_begin;
 		//We have a plist to parse
 			if (verbose > 1)
 			printf("reading property list, %llu bytes from address %llu ...\n", (unsigned long long)kolyblk.XMLLength, (unsigned long long)kolyblk.XMLOffset);
@@ -229,7 +231,7 @@ int main(int argc, char *argv[])
 		if (debug && verbose >= 3) {
 			fprintf(FDBG, "%s\n", plist);
 		}
-		char *_blkx_begin = strstr(plist, blkx_begin);
+		_blkx_begin = strstr(plist, blkx_begin);
 		blkx_size = strstr(_blkx_begin, list_end) - _blkx_begin;
 		blkx = (char *)malloc(blkx_size + 1);
 		memcpy(blkx, _blkx_begin, blkx_size);
@@ -245,6 +247,7 @@ int main(int argc, char *argv[])
 		scb = strlen(chunk_begin);
 		while (1) {
 			unsigned int tmplen;
+			char *base64data;
 			data_begin = strstr(data_begin, chunk_begin);
 			if (!data_begin)
 				break;
@@ -258,7 +261,7 @@ int main(int argc, char *argv[])
 			if (!parts)
 				mem_overflow();
 
-			char *base64data = (char *)malloc(data_size + 1);
+			base64data = (char *)malloc(data_size + 1);
 			if (!base64data)
 				mem_overflow();
 			base64data[data_size] = '\0';
@@ -295,6 +298,8 @@ int main(int argc, char *argv[])
 				printf("partition %d: %s\n", i, partname);
 		}
 	} else if (kolyblk.RsrcForkOffset != 0 && kolyblk.RsrcForkLength != 0) {
+		struct _mishblk mishblk;
+		int next_mishblk;
 		//We have a binary resource fork to parse
 			plist = (char *)malloc(kolyblk.RsrcForkLength);
 		if (!plist)
@@ -302,8 +307,7 @@ int main(int argc, char *argv[])
 		fseeko(FIN, kolyblk.RsrcForkOffset, SEEK_SET);
 		fread(plist, kolyblk.RsrcForkLength, 1, FIN);
 		partnum = 0;
-		struct _mishblk mishblk;
-		int next_mishblk = 0;
+		next_mishblk = 0;
 		mish_begin = plist + 0x104;
 		while (1) {
 			mish_begin += next_mishblk;
@@ -377,6 +381,7 @@ int main(int argc, char *argv[])
 	in_offs = add_offs = in_offs_add = kolyblk.DataForkOffset;
 
 	for (i = extractpart==-1?0:extractpart; i < (extractpart==-1?partnum:extractpart+1) && in_offs <= kolyblk.DataForkLength - kolyblk.DataForkOffset; i++) {
+		unsigned long bi;
 		if (verbose)
 			printf("opening partition %d ...           ", i);
 		if (verbose >= 3)
@@ -390,7 +395,7 @@ int main(int argc, char *argv[])
 		if (debug) {
 			fprintf(FDBG, "\n   run..... ..type.... ..reserved ..sectorStart..... ..sectorCount..... ..compOffset...... ..compLength......\n");
 		}
-		unsigned long bi = 0;
+		bi = 0;
 		while (block_type != BT_TERM && offset < parts[i].BlocksRunCount * 0x28) {
 			block_type = convert_char4((unsigned char *)parts[i].Data + offset);
 			dw_reserved = convert_char4((unsigned char *)parts[i].Data + offset + 4);
@@ -552,14 +557,14 @@ int main(int argc, char *argv[])
 				fseeko(FIN, in_offs + add_offs, SEEK_SET);
 				to_read = in_size;
 				while (to_read > 0) {
+					int bytes_written, read_from_input;
 					chunk = to_read > CHUNKSIZE ? CHUNKSIZE : to_read;
 					to_write = fread(tmp, 1, chunk, FIN);
 					if (ferror(FIN) || to_write < chunk) {
 						printf("ERROR: reading file %s\n", input_file);
 						return 1;
 					}
-					int bytes_written;
-					int read_from_input = adc_decompress(to_write, tmp, DECODEDSIZE, dtmp, &bytes_written);
+					read_from_input = adc_decompress(to_write, tmp, DECODEDSIZE, dtmp, &bytes_written);
 					fwrite(dtmp, 1, bytes_written, FOUT);
 					to_read -= read_from_input;
 				}
diff --git a/mntcmd.h b/mntcmd.h
index 0e3a8fe..7c7da52 100644
--- a/mntcmd.h
+++ b/mntcmd.h
@@ -19,16 +19,17 @@ void read_gpt_entry(FILE * F, struct _gpt_entry *e)
 
 int print_mountcmd(char *filename)
 {
-	if (!filename)
-		return (-1);
-
 	unsigned int i, pn = 0;
 	char tmp[128];
 	struct _gpt_header gpt_header;
 	struct _gpt_entry gpt_entry;
 	struct _gpt_entry *gpt_ent_array;
+	FILE *F;
+
+	if (!filename)
+		return (-1);
 
-	FILE *F = fopen(filename, "rb");
+	F = fopen(filename, "rb");
 	fseeko(F, 0x200, SEEK_SET);
 	read_gpt_header(F, &gpt_header);
 
-- 
2.14.2

