From b9bf65b589daafa2c7db4f0cbe4d6ca9651b6695 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 31 Jul 2025 19:47:00 -0500 Subject: [PATCH] Cleanup: Relocate local variables into block. The variable should be in a block so that they only exist as long as they need to. --- level_2/fll_program/c/program.c | 122 +++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 59 deletions(-) diff --git a/level_2/fll_program/c/program.c b/level_2/fll_program/c/program.c index cdad9cf..5bef012 100644 --- a/level_2/fll_program/c/program.c +++ b/level_2/fll_program/c/program.c @@ -432,91 +432,95 @@ extern "C" { // 0x10 = output descriptor, 0x20 = error descriptor, 0x40 = input descriptor. flag = 0; - f_file_t file = f_file_t_initialize; + { + f_file_t file = f_file_t_initialize; - if (F_type_output_d) { - file.stream = F_type_output_d; - flag |= 0x1; + if (F_type_output_d) { + file.stream = F_type_output_d; + flag |= 0x1; - f_file_stream_flush(file); - } - else { - if (F_type_descriptor_output_d != -1) { - file.id = F_type_descriptor_output_d; - flag |= 0x20; + f_file_stream_flush(file); + } + else { + if (F_type_descriptor_output_d != -1) { + file.id = F_type_descriptor_output_d; + flag |= 0x20; - f_file_flush(file); + f_file_flush(file); + } } - } - if (F_type_error_d) { - file.stream = F_type_error_d; - flag |= 0x2; + if (F_type_error_d) { + file.stream = F_type_error_d; + flag |= 0x2; - f_file_stream_flush(file); - } - else { - if (F_type_descriptor_error_d != -1) { - file.id = F_type_descriptor_output_d; - flag |= 0x40; + f_file_stream_flush(file); + } + else { + if (F_type_descriptor_error_d != -1) { + file.id = F_type_descriptor_output_d; + flag |= 0x40; - f_file_flush(file); + f_file_flush(file); + } } - } - if (F_type_input_d) { - file.stream = F_type_input_d; - flag |= 0x4; + if (F_type_input_d) { + file.stream = F_type_input_d; + flag |= 0x4; - f_file_stream_flush(file); - } - else { - if (F_type_descriptor_input_d != -1) { - file.id = F_type_descriptor_input_d; - flag |= 0x80; + f_file_stream_flush(file); + } + else { + if (F_type_descriptor_input_d != -1) { + file.id = F_type_descriptor_input_d; + flag |= 0x80; - f_file_flush(file); + f_file_flush(file); + } } - } - if (flag & 0x1) { - file.stream = F_type_output_d; + if (flag & 0x1) { + file.stream = F_type_output_d; - f_file_stream_close(&file); - } + f_file_stream_close(&file); + } - if (flag & 0x2) { - file.stream = F_type_error_d; + if (flag & 0x2) { + file.stream = F_type_error_d; - f_file_stream_close(&file); - } + f_file_stream_close(&file); + } - if (flag & 0x4) { - file.stream = F_type_input_d; + if (flag & 0x4) { + file.stream = F_type_input_d; - f_file_stream_close(&file); - } + f_file_stream_close(&file); + } - if (flag & 0x10) { - file.id = F_type_descriptor_output_d; + if (flag & 0x10) { + file.id = F_type_descriptor_output_d; - f_file_close(&file); - } + f_file_close(&file); + } - if (flag & 0x20) { - file.id = F_type_descriptor_error_d; + if (flag & 0x20) { + file.id = F_type_descriptor_error_d; - f_file_close(&file); - } + f_file_close(&file); + } - if (flag & 0x40) { - file.id = F_type_descriptor_input_d; + if (flag & 0x40) { + file.id = F_type_descriptor_input_d; - f_file_close(&file); + f_file_close(&file); + } } - const f_status_t status = f_signal_close(&program->signal); - if (F_status_is_error(status)) return status; + { + const f_status_t status = f_signal_close(&program->signal); + if (F_status_is_error(status)) return status; + } return F_okay; } -- 1.8.3.1