1
0
mirror of https://git.disroot.org/80486DX2-66/polonium.git synced 2024-11-09 06:02:41 +05:30

corrupter.c: fix error handling

This commit is contained in:
Intel A80486DX2-66 2024-07-20 00:19:13 +03:00
parent f9d691b8fc
commit c19192b00b
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -103,7 +103,8 @@ Corrupter_Result* corrupt_file(Corrupter_Param* param) {
for (file_offset_t i = start; i < end; i += 3) {
FSEEK_MACRO(file, i, SEEK_SET);
byte byte_values[3];
if (fread(&byte_values, sizeof(byte), 3, file) != 3) {
size_t ret_value = fread(&byte_values, sizeof(byte), 3, file);
if (ret_value == 0 || ret_value > 3) {
result->error = true;
fclose(file);
return result;
@ -144,13 +145,13 @@ Corrupter_Result* corrupt_file(Corrupter_Param* param) {
// write the modified byte back to the file
FSEEK_MACRO(file, i, SEEK_SET);
if (fwrite(&byte_values, sizeof(byte), 3, file) == 3)
continue;
// on error
result->error = true;
fclose(file);
return result;
size_t ret_value = fwrite(&byte_values, sizeof(byte), 3, file);
if (ret_value == 0 || ret_value > 3) {
// on error
result->error = true;
fclose(file);
return result;
}
}
if (damaged_byte)