diff --git a/src/minivhd/minivhd_convert.c b/src/minivhd/minivhd_convert.c index 8e712e4..1b4f4f0 100644 --- a/src/minivhd/minivhd_convert.c +++ b/src/minivhd/minivhd_convert.c @@ -64,8 +64,8 @@ MVHDMeta* mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const char* utf8 uint8_t buff[4096] = {0}; // 8 sectors uint8_t empty_buff[4096] = {0}; int total_sectors = mvhd_calc_size_sectors(&geom); - int copy_sect = 0; - for (int i = 0; i < total_sectors; i += 8) { + int copy_sect = 0, i; + for (i = 0; i < total_sectors; i += 8) { copy_sect = 8; if ((i + 8) >= total_sectors) { copy_sect = total_sectors - i; @@ -93,8 +93,8 @@ FILE* mvhd_convert_to_raw(const char* utf8_vhd_path, const char* utf8_raw_path, } uint8_t buff[4096] = {0}; // 8 sectors int total_sectors = mvhd_calc_size_sectors((MVHDGeom*)&vhdm->footer.geom); - int copy_sect = 0; - for (int i = 0; i < total_sectors; i += 8) { + int copy_sect = 0, i; + for (i = 0; i < total_sectors; i += 8) { copy_sect = 8; if ((i + 8) >= total_sectors) { copy_sect = total_sectors - i; diff --git a/src/minivhd/minivhd_create.c b/src/minivhd/minivhd_create.c index c1725c4..9bb63c1 100644 --- a/src/minivhd/minivhd_create.c +++ b/src/minivhd/minivhd_create.c @@ -356,7 +356,8 @@ static MVHDMeta* mvhd_create_sparse_diff(const char* path, const char* par_path, mvhd_header_to_buffer(&vhdm->sparse, sparse_buff); fwrite(sparse_buff, sizeof sparse_buff, 1, f); /* The BAT sectors need to be filled with 0xffffffff */ - for (uint32_t i = 0; i < num_bat_sect; i++) { + uint32_t i; + for (i = 0; i < num_bat_sect; i++) { fwrite(bat_sect, sizeof bat_sect, 1, f); } mvhd_write_empty_sectors(f, 5); @@ -370,8 +371,10 @@ static MVHDMeta* mvhd_create_sparse_diff(const char* path, const char* par_path, assert(curr_pos == par_loc_offset); /* Fill the space required for location data with zero */ uint8_t empty_sect[MVHD_SECTOR_SIZE] = {0}; - for (int i = 0; i < 2; i++) { - for (uint32_t j = 0; j < (vhdm->sparse.par_loc_entry[i].plat_data_space / MVHD_SECTOR_SIZE); j++) { + int i; + uint32_t j; + for (i = 0; i < 2; i++) { + for (j = 0; j < (vhdm->sparse.par_loc_entry[i].plat_data_space / MVHD_SECTOR_SIZE); j++) { fwrite(empty_sect, sizeof empty_sect, 1, f); } } diff --git a/src/minivhd/minivhd_io.c b/src/minivhd/minivhd_io.c index 4169d66..c21f68d 100644 --- a/src/minivhd/minivhd_io.c +++ b/src/minivhd/minivhd_io.c @@ -45,7 +45,8 @@ static inline void mvhd_check_sectors(uint32_t offset, int num_sectors, uint32_t void mvhd_write_empty_sectors(FILE* f, int sector_count) { uint8_t zero_bytes[MVHD_SECTOR_SIZE] = {0}; - for (int i = 0; i < sector_count; i++) { + int i; + for (i = 0; i < sector_count; i++) { fwrite(zero_bytes, sizeof zero_bytes, 1, f); } } @@ -126,7 +127,8 @@ static void mvhd_create_block(MVHDMeta* vhdm, int blk) { /* Yikes! We're supposed to be on a sector boundary. Add some padding */ int64_t padding_amount = (int64_t)MVHD_SECTOR_SIZE - (abs_offset % MVHD_SECTOR_SIZE); uint8_t zero_byte = 0; - for (int i = 0; i < padding_amount; i++) { + int i; + for (i = 0; i < padding_amount; i++) { fwrite(&zero_byte, sizeof zero_byte, 1, vhdm->f); } abs_offset += padding_amount; diff --git a/src/minivhd/minivhd_manage.c b/src/minivhd/minivhd_manage.c index 97eed8e..d852a94 100644 --- a/src/minivhd/minivhd_manage.c +++ b/src/minivhd/minivhd_manage.c @@ -103,7 +103,8 @@ static int mvhd_read_bat(MVHDMeta *vhdm, MVHDError* err) { return -1; } mvhd_fseeko64(vhdm->f, vhdm->sparse.bat_offset, SEEK_SET); - for (uint32_t i = 0; i < vhdm->sparse.max_bat_ent; i++) { + uint32_t i; + for (i = 0; i < vhdm->sparse.max_bat_ent; i++) { fread(&vhdm->block_offset[i], sizeof *vhdm->block_offset, 1, vhdm->f); vhdm->block_offset[i] = mvhd_from_be32(vhdm->block_offset[i]); } @@ -239,7 +240,8 @@ static char* mvhd_get_diff_parent_path(MVHDMeta* vhdm, int* err) { } /* Now read the parent locator entries, both relative and absolute, if they exist */ unsigned char* loc_path; - for (int i = 0; i < 8; i++) { + int i; + for (i = 0; i < 8; i++) { utf_outlen = MVHD_MAX_PATH_BYTES - 1; if (vhdm->sparse.par_loc_entry[i].plat_code == MVHD_DIF_LOC_W2RU) { loc_path = (unsigned char*)paths->w2ru_path; @@ -526,7 +528,8 @@ int mvhd_write_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* i int mvhd_format_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors) { int num_full = num_sectors / vhdm->format_buffer.sector_count; int remain = num_sectors % vhdm->format_buffer.sector_count; - for (int i = 0; i < num_full; i++) { + int i; + for (i = 0; i < num_full; i++) { vhdm->write_sectors(vhdm, offset, vhdm->format_buffer.sector_count, vhdm->format_buffer.zero_data); offset += vhdm->format_buffer.sector_count; } diff --git a/src/minivhd/minivhd_struct_rw.c b/src/minivhd/minivhd_struct_rw.c index bef6590..77f26a4 100644 --- a/src/minivhd/minivhd_struct_rw.c +++ b/src/minivhd/minivhd_struct_rw.c @@ -133,7 +133,8 @@ void mvhd_buffer_to_header(MVHDSparseHeader* header, uint8_t* buffer) { mvhd_next_buffer_to_struct(&header->par_timestamp, sizeof header->par_timestamp, true, &buff_ptr); mvhd_next_buffer_to_struct(&header->reserved_1, sizeof header->reserved_1, true, &buff_ptr); mvhd_next_buffer_to_struct(&header->par_utf16_name, sizeof header->par_utf16_name, false, &buff_ptr); - for (int i = 0; i < 8; i++) { + int i; + for (i = 0; i < 8; i++) { mvhd_next_buffer_to_struct(&header->par_loc_entry[i].plat_code, sizeof header->par_loc_entry[i].plat_code, true, &buff_ptr); mvhd_next_buffer_to_struct(&header->par_loc_entry[i].plat_data_space, sizeof header->par_loc_entry[i].plat_data_space, true, &buff_ptr); mvhd_next_buffer_to_struct(&header->par_loc_entry[i].plat_data_len, sizeof header->par_loc_entry[i].plat_data_len, true, &buff_ptr); @@ -156,7 +157,8 @@ void mvhd_header_to_buffer(MVHDSparseHeader* header, uint8_t* buffer) { mvhd_next_struct_to_buffer(&header->par_timestamp, sizeof header->par_timestamp, true, &buff_ptr); mvhd_next_struct_to_buffer(&header->reserved_1, sizeof header->reserved_1, true, &buff_ptr); mvhd_next_struct_to_buffer(&header->par_utf16_name, sizeof header->par_utf16_name, false, &buff_ptr); - for (int i = 0; i < 8; i++) { + int i; + for (i = 0; i < 8; i++) { mvhd_next_struct_to_buffer(&header->par_loc_entry[i].plat_code, sizeof header->par_loc_entry[i].plat_code, true, &buff_ptr); mvhd_next_struct_to_buffer(&header->par_loc_entry[i].plat_data_space, sizeof header->par_loc_entry[i].plat_data_space, true, &buff_ptr); mvhd_next_struct_to_buffer(&header->par_loc_entry[i].plat_data_len, sizeof header->par_loc_entry[i].plat_data_len, true, &buff_ptr); diff --git a/src/minivhd/minivhd_util.c b/src/minivhd/minivhd_util.c index cd7d446..b04e022 100644 --- a/src/minivhd/minivhd_util.c +++ b/src/minivhd/minivhd_util.c @@ -94,7 +94,8 @@ void mvhd_generate_uuid(uint8_t* uuid) { /* We aren't doing crypto here, so using system time as seed should be good enough */ srand((unsigned int)time(0)); - for (int n = 0; n < 16; n++) { + int n; + for (n = 0; n < 16; n++) { uuid[n] = rand(); } uuid[6] &= 0x0F; @@ -196,7 +197,8 @@ uint32_t mvhd_gen_footer_checksum(MVHDFooter* footer) { uint32_t orig_chk = footer->checksum; footer->checksum = 0; uint8_t* footer_bytes = (uint8_t*)footer; - for (size_t i = 0; i < sizeof *footer; i++) { + size_t i; + for (i = 0; i < sizeof *footer; i++) { new_chk += footer_bytes[i]; } footer->checksum = orig_chk; @@ -208,7 +210,8 @@ uint32_t mvhd_gen_sparse_checksum(MVHDSparseHeader* header) { uint32_t orig_chk = header->checksum; header->checksum = 0; uint8_t* sparse_bytes = (uint8_t*)header; - for (size_t i = 0; i < sizeof *header; i++) { + size_t i; + for (i = 0; i < sizeof *header; i++) { new_chk += sparse_bytes[i]; } header->checksum = orig_chk; @@ -279,19 +282,21 @@ int mvhd_fseeko64(FILE* stream, int64_t offset, int origin) } uint32_t mvhd_crc32_for_byte(uint32_t r) { - for (int j = 0; j < 8; ++j) + int j; + for (j = 0; j < 8; ++j) r = (r & 1 ? 0 : (uint32_t)0xEDB88320L) ^ r >> 1; return r ^ (uint32_t)0xFF000000L; } uint32_t mvhd_crc32(const void* data, size_t n_bytes) { static uint32_t table[0x100]; + size_t i; if (!*table) - for (size_t i = 0; i < 0x100; ++i) + for (i = 0; i < 0x100; ++i) table[i] = mvhd_crc32_for_byte(i); uint32_t crc = 0; - for (size_t i = 0; i < n_bytes; ++i) + for (i = 0; i < n_bytes; ++i) crc = table[(uint8_t)crc ^ ((uint8_t*)data)[i]] ^ crc >> 8; return crc;