Remove C99 declarations in for loops from MiniVHD. Patch from Greatpsycho.

This commit is contained in:
SarahW 2020-11-26 08:39:54 +00:00
commit 0ec9c6e728
6 changed files with 35 additions and 20 deletions

View file

@ -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;