diff --git a/src/corrupter.c b/src/corrupter.c index b2ad54e..f387b14 100644 --- a/src/corrupter.c +++ b/src/corrupter.c @@ -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)