From 098644abe5a670861b2a952a0713c7e547e47754 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Fri, 22 Nov 2024 18:33:55 +0300 Subject: [PATCH] post-merge fixes --- src/corrupter.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/corrupter.c b/src/corrupter.c index 7b954e0..7647e19 100644 --- a/src/corrupter.c +++ b/src/corrupter.c @@ -36,13 +36,12 @@ static bool is_line_ending(byte c) { void corrupt_byte(Interoperation_Input_Vars) { uint8_t config = param->config; - FSEEK_MACRO(file, i, SEEK_SET); byte byte_value = buffer[i]; if (READ_CONFIG(C_PRINTABLE) && !isprint(byte_value)) - return INTEROPERATION_SUCCESS; + return; else if (READ_CONFIG(C_LINE_ENDINGS) && is_line_ending(byte_value)) - return INTEROPERATION_SUCCESS; + return; // generate bit mask byte threshold = param->threshold, @@ -69,8 +68,6 @@ void corrupt_byte(Interoperation_Input_Vars) { result->damaged_bytes++; } - - return INTEROPERATION_SUCCESS; } Corrupter_Result corrupt_file(Corrupter_Param* param) { @@ -135,10 +132,12 @@ Corrupter_Result corrupt_file(Corrupter_Param* param) { rewind(file); // allocate memory for the file content - uint8_t* buffer = malloc(end); + byte* buffer = malloc(end); if (buffer == NULL) { - result->error = true; + PERROR_MACRO("malloc"); + + result.error = true; return result; } @@ -146,16 +145,12 @@ Corrupter_Result corrupt_file(Corrupter_Param* param) { if (fread(buffer, 1, end, file) != (size_t) end) { free(buffer); - if (feof(file)) { + if (feof(file)) ERROR_MSG("fread", "End of file reached"); + else + PERROR_MACRO("fread"); - fclose(file); - free(result); - exit(EXIT_FAILURE); - } - - fclose(file); - result->error = true; + result.error = true; return result; } @@ -175,12 +170,25 @@ Corrupter_Result corrupt_file(Corrupter_Param* param) { // iterate over the file contents for (file_offset_t i = start; i < end; i++) CORRUPT_BYTE_MACRO; + } - puts(" [OK]"); + // write the buffer to the file + rewind(file); + + if (fwrite(buffer, 1, end, file) != (size_t) end) { + free(buffer); + + if (feof(file)) + ERROR_MSG("fwrite", "End of file reached"); + else + PERROR_MACRO("fwrite"); + + result.error = true; + return result; } free(buffer); - result->error = false; + result.error = false; return result; }