Mercurial > hg > sidinfo
comparison sidinfo.c @ 8:cfc74ec918dc
Fix handling of "large" SID files.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 25 Sep 2014 02:07:38 +0300 |
parents | 36c43f085b28 |
children | c1fba4abf56f |
comparison
equal
deleted
inserted
replaced
7:36c43f085b28 | 8:cfc74ec918dc |
---|---|
349 first = TRUE; | 349 first = TRUE; |
350 do | 350 do |
351 { | 351 { |
352 read = fread(fileData, sizeof(uint8_t), PSID_BUFFER_SIZE, inFile); | 352 read = fread(fileData, sizeof(uint8_t), PSID_BUFFER_SIZE, inFile); |
353 psid->dataSize += read; | 353 psid->dataSize += read; |
354 if (read < 16) | |
355 { | |
356 THERR("Error reading song data, unexpectedly small file.\n"); | |
357 goto error; | |
358 } | |
359 | 354 |
360 if (first && psid->loadAddress == 0) | 355 if (first && psid->loadAddress == 0) |
361 { | 356 { |
357 if (read < 4) | |
358 { | |
359 THERR("Error reading song data, unexpectedly small file.\n"); | |
360 goto error; | |
361 } | |
362 | |
362 // Strip load address (2 first bytes) | 363 // Strip load address (2 first bytes) |
363 th_md5_append(&state, &fileData[2], read - 2); | 364 th_md5_append(&state, &fileData[2], read - 2); |
364 first = FALSE; | 365 first = FALSE; |
365 } | 366 } |
366 else | 367 else |
368 if (read > 0) | |
367 { | 369 { |
368 // Append "as is" | 370 // Append "as is" |
369 th_md5_append(&state, fileData, read); | 371 th_md5_append(&state, fileData, read); |
370 } | 372 } |
371 } while (read > 0 && !feof(inFile)); | 373 } while (read > 0 && !feof(inFile)); |