From b38f3c212c09e2a4845c4cced503ce6cfee8fd9e Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 14 Sep 2019 22:41:48 -0500 Subject: [PATCH] Update: int8_t and uint8_t are always size 1, so avoid sizeof(int8_t) and sizeof(uint8_t) calculations --- level_0/f_file/c/file.h | 2 +- level_0/f_utf/c/utf.c | 4 ++-- level_1/fl_directory/c/directory.c | 2 +- level_1/fl_fss/c/fss.h | 4 ++-- level_1/fl_serialized/c/serialized.c | 6 +++--- level_1/fl_string/c/string.c | 2 +- level_2/fll_execute/c/execute.c | 4 ++-- level_3/firewall/c/firewall.c | 6 +++--- level_3/firewall/c/private-firewall.h | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index 66b86e2..24be5b8 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -85,7 +85,7 @@ extern "C" { f_file_mode mode; } f_file; - #define f_file_initialize { 0, sizeof(int8_t), 0, (f_file_mode) f_file_read_only } + #define f_file_initialize { 0, 1, 0, (f_file_mode) f_file_read_only } #endif // _di_f_file_ /** diff --git a/level_0/f_utf/c/utf.c b/level_0/f_utf/c/utf.c index 840911b..86ec9ac 100644 --- a/level_0/f_utf/c/utf.c +++ b/level_0/f_utf/c/utf.c @@ -1633,7 +1633,7 @@ extern "C" { *max_width = width; if (f_utf_is_big_endian()) { - memcpy(*character, &utf_character, sizeof(int8_t) * width); + memcpy(*character, &utf_character, width); } else { uint32_t utf = 0; @@ -1651,7 +1651,7 @@ extern "C" { utf = (f_macro_utf_character_to_char_4(utf_character) << 24) | (f_macro_utf_character_to_char_3(utf_character) << 16) | (f_macro_utf_character_to_char_2(utf_character) << 8) | f_macro_utf_character_to_char_1(utf_character); } - memcpy(*character, &utf, sizeof(int8_t) * width); + memcpy(*character, &utf, width); } return f_none; diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index 3e7d760..4b26f8e 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -37,7 +37,7 @@ extern "C" { return status; } - memcpy(names->array[names->used].string, listing[counter]->d_name, sizeof(int8_t) * size); + memcpy(names->array[names->used].string, listing[counter]->d_name, size); names->array[names->used].used = size; names->used++; } diff --git a/level_1/fl_fss/c/fss.h b/level_1/fl_fss/c/fss.h index 4dede3c..ccf0bc5 100644 --- a/level_1/fl_fss/c/fss.h +++ b/level_1/fl_fss/c/fss.h @@ -42,7 +42,7 @@ extern "C" { * The number of steps to decrement the start position. * The steps refer to characters and not integers. * Essentially this number is considered against the width of every character found. - * (For ASCII each step would be (sizeof(int8_t)). + * (For ASCII each step would be (sizeof(int8_t), which is 1). * (For UTF-8 character of width 3, each step would be (3 * sizeof(int8_t)). * * @return @@ -113,7 +113,7 @@ extern "C" { * The number of steps to increment the start position. * The steps refer to characters and not integers. * Essentially this number is considered against the width of every character found. - * (For ASCII each step would be (sizeof(int8_t)). + * (For ASCII each step would be (sizeof(int8_t), which is 1). * (For UTF-8 character of width 3, each step would be (3 * sizeof(int8_t)). * * @return diff --git a/level_1/fl_serialized/c/serialized.c b/level_1/fl_serialized/c/serialized.c index dabd7be..1a5a79f 100644 --- a/level_1/fl_serialized/c/serialized.c +++ b/level_1/fl_serialized/c/serialized.c @@ -19,12 +19,12 @@ extern "C" { } if (serialized->used == 0) { - memcpy(serialized->string + serialized->used, value.string, sizeof(int8_t) * value.used); + memcpy(serialized->string + serialized->used, value.string, value.used); serialized->used += value.used; } else { - memcpy(serialized->string + serialized->used, f_serialized_simple_splitter_string, sizeof(int8_t)); - memcpy(serialized->string + serialized->used + 1, value.string, sizeof(int8_t) * value.used); + memcpy(serialized->string + serialized->used, f_serialized_simple_splitter_string, 1); + memcpy(serialized->string + serialized->used + 1, value.string, value.used); serialized->used += value.used + 1; } diff --git a/level_1/fl_string/c/string.c b/level_1/fl_string/c/string.c index c960bb2..008bfcd 100644 --- a/level_1/fl_string/c/string.c +++ b/level_1/fl_string/c/string.c @@ -30,7 +30,7 @@ extern "C" { return status; } - memcpy(result->string, buffer.string + location.start, sizeof(int8_t) * size); + memcpy(result->string, buffer.string + location.start, size); result->used = size; return f_none; diff --git a/level_2/fll_execute/c/execute.c b/level_2/fll_execute/c/execute.c index 01f0c2f..9914b40 100644 --- a/level_2/fll_execute/c/execute.c +++ b/level_2/fll_execute/c/execute.c @@ -65,7 +65,7 @@ extern "C" { return status; } - memcpy(fixed_arguments[i + 1], arguments.array[i].string, sizeof(int8_t) * arguments.array[i].used); + memcpy(fixed_arguments[i + 1], arguments.array[i].string, arguments.array[i].used); fixed_arguments[i + 1][arguments.array[i].used] = f_string_eos; } // for @@ -145,7 +145,7 @@ extern "C" { return status; } - memcpy(fixed_arguments[i + 1], arguments.array[i].string, sizeof(int8_t) * arguments.array[i].used); + memcpy(fixed_arguments[i + 1], arguments.array[i].string, arguments.array[i].used); fixed_arguments[i + 1][arguments.array[i].used] = f_string_eos; } // for diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index 089ec06..33ce463 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -534,9 +534,9 @@ extern "C" { return status; } - memcpy((void *)file_path.string, network_path, sizeof(int8_t) * network_path_length); - memcpy((void *)(file_path.string + network_path_length), data->devices.array[i].string, sizeof(int8_t) * data->devices.array[i].used); - memcpy((void *)(file_path.string + network_path_length + data->devices.array[i].used), firewall_file_suffix, sizeof(int8_t) * firewall_file_suffix_length); + memcpy((void *)file_path.string, network_path, network_path_length); + memcpy((void *)(file_path.string + network_path_length), data->devices.array[i].string, data->devices.array[i].used); + memcpy((void *)(file_path.string + network_path_length + data->devices.array[i].used), firewall_file_suffix, firewall_file_suffix_length); file_path.used = network_path_length + data->devices.array[i].used + firewall_file_suffix_length; file_path.string[file_path.used] = 0; diff --git a/level_3/firewall/c/private-firewall.h b/level_3/firewall/c/private-firewall.h index 4114896..1ba3f9d 100644 --- a/level_3/firewall/c/private-firewall.h +++ b/level_3/firewall/c/private-firewall.h @@ -74,7 +74,7 @@ typedef struct { f_macro_fss_contents_delete(status, contents); #define firewall_macro_concat_string(destination, source, length) \ - memcpy((void *)(destination), source, sizeof(int8_t) * length); + memcpy((void *)(destination), source, length); #define firewall_macro_rule_contents_has_incorrect_items(index, total_items) \ local.rule_contents.array[index].used <= 0 || local.rule_contents.array[index].used > total_items -- 1.8.3.1