From ea6a47d2ee568e31b72574b09ccd8de95abd08bb Mon Sep 17 00:00:00 2001 From: TheVice Date: Tue, 2 Apr 2024 23:03:48 +0300 Subject: [PATCH] [GCC|Clang] added addition compile flags. Added addition checks of source code, and globally change it to meet such requirements. This flags is the same like in https://github.com/Cyan4973/FiniteStateEntropy.git repository at the make file. [argument_parser|buffer|common|date_time|environment|file_system|interpreter|interpreter.file_system|interpreter.path|interpreter.property|interpreter.string_unit|load_tasks|operating_system] 'void' key word required in functions that do not have any parameters. [buffer] added buffer_data_finish function - will help in some scenario where casting required with end of buffer data point. See changes at the xml unit to see what problem is solving with this function. [environment] added missed cases for non Windows platform - new compile flag signal that default not enough in scenario when we do need processing some of cases from the enum in the switch operator. [exec|load_tasks|property|text_encoding|version] deal with casting of pointers when align policy is required to do so with adding variable with required type or use correct already exists one if that possible. [load_file] resolve prohibited casting with using of recently added function - text_encoding_UTF_to_UTF8. [path] added required const modifier to the declaration of variable. [sleep_unit] added missed casting. [text_encoding] added text_encoding_UTF16_to_ASCII, text_encoding_UTF32_to_ASCII, text_encoding_UTF16_to_UTF8, text_encoding_UTF32_to_UTF8 and text_encoding_UTF_to_UTF8 functions. [tests_file_system] replaced #if TODO with #if defined(TODO) in order to meet requirements from compiler with recently added flags. [tests_text_encoding] added test on text_encoding_UTF_to_UTF8 and text_encoding_get_one functions. [xml] deal with pointer arithmetics and later casting to the different type with using recently added function. --- CMakeLists.txt | 12 +- argument_parser.c | 32 ++-- argument_parser.h | 32 ++-- bit_converter.c | 2 +- bit_converter.h | 2 +- buffer.c | 17 ++- buffer.h | 7 +- common.c | 12 +- common.h | 10 +- date_time.c | 8 +- date_time.h | 10 +- environment.c | 49 +++++- environment.h | 10 +- exec.c | 7 +- file_system.c | 2 +- interpreter.c | 4 +- interpreter.file_system.c | 22 +-- interpreter.file_system.h | 22 +-- interpreter.h | 6 +- interpreter.path.c | 4 +- interpreter.property.c | 4 +- interpreter.property.h | 4 +- interpreter.string_unit.c | 12 +- interpreter.string_unit.h | 12 +- load_file.c | 76 +++++----- load_tasks.c | 13 +- operating_system.c | 10 +- operating_system.h | 12 +- path.c | 2 +- property.c | 4 +- sleep_unit.c | 4 +- tests.cmake | 8 +- tests.xml | 125 ++++++++++++++++ tests_file_system.cpp | 4 +- tests_text_encoding.cpp | 90 ++++++++++- text_encoding.c | 305 +++++++++++++++++++++++++++++++++++--- text_encoding.h | 9 +- version.c | 19 ++- xml.c | 6 +- 39 files changed, 769 insertions(+), 220 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index be4057b..98f49ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,8 +147,8 @@ if(NOT MSVC) endif() target_compile_options(ant4c PRIVATE - $<$:-Wall -Wextra -Werror> - $<$:-Wall -Wextra -Werror> + $<$:-Wall -Wextra -Werror -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wstrict-prototypes -Wundef> + $<$:-Wall -Wextra -Werror -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wstrict-prototypes -Wundef> $<$:/W4 /WX> ) @@ -178,8 +178,8 @@ if(NOT MSVC) endif() target_compile_options(ant4c_shared PRIVATE - $<$:-Wall -Wextra -Werror> - $<$:-Wall -Wextra -Werror> + $<$:-Wall -Wextra -Werror -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wstrict-prototypes -Wundef> + $<$:-Wall -Wextra -Werror -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wstrict-prototypes -Wundef> $<$:/W4 /WX> ) @@ -221,8 +221,8 @@ if(NOT MSVC) endif() target_compile_options(ant4c_app PRIVATE - $<$:-Wall -Wextra -Werror> - $<$:-Wall -Wextra -Werror> + $<$:-Wall -Wextra -Werror -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wstrict-prototypes -Wundef> + $<$:-Wall -Wextra -Werror -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wstrict-prototypes -Wundef> $<$:/W4 /WX> ) diff --git a/argument_parser.c b/argument_parser.c index 9a11c8f..cb33450 100644 --- a/argument_parser.c +++ b/argument_parser.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -553,7 +553,7 @@ uint8_t argument_parser_wchar_t(int i, int argc, wchar_t** argv) return 1; } #endif -uint8_t argument_parser_init() +uint8_t argument_parser_init(void) { if (!is_init) { @@ -802,57 +802,57 @@ const uint8_t* argument_parser_get_null_terminated_by_index( return finish != start ? start : NULL; } -uint8_t argument_parser_get_debug() +uint8_t argument_parser_get_debug(void) { return parameters_.debug; } -uint8_t argument_parser_get_indent() +uint8_t argument_parser_get_indent(void) { return parameters_.indent; } -uint8_t argument_parser_get_module_priority() +uint8_t argument_parser_get_module_priority(void) { return parameters_.module_priority; } -uint8_t argument_parser_get_no_logo() +uint8_t argument_parser_get_no_logo(void) { return parameters_.no_logo; } -uint8_t argument_parser_get_pause() +uint8_t argument_parser_get_pause(void) { return parameters_.pause; } -uint8_t argument_parser_get_program_help() +uint8_t argument_parser_get_program_help(void) { return parameters_.program_help; } -uint8_t argument_parser_get_project_help() +uint8_t argument_parser_get_project_help(void) { return parameters_.project_help; } -uint8_t argument_parser_get_quiet() +uint8_t argument_parser_get_quiet(void) { return parameters_.quiet; } -uint8_t argument_parser_get_verbose() +uint8_t argument_parser_get_verbose(void) { return parameters_.verbose; } -uint16_t argument_parser_get_encoding() +uint16_t argument_parser_get_encoding(void) { return parameters_.encoding; } -const void* argument_parser_get_properties() +const void* argument_parser_get_properties(void) { return (const void*)(¶meters_.properties); } @@ -862,7 +862,7 @@ const uint8_t* argument_parser_get_build_file(int index) return argument_parser_get_null_terminated_by_index((void*)(¶meters_.build_file), index); } -const uint8_t* argument_parser_get_log_file() +const uint8_t* argument_parser_get_log_file(void) { return buffer_uint8_t_data((void*)(¶meters_.log_file), 0); } @@ -872,12 +872,12 @@ const uint8_t* argument_parser_get_target(int index) return argument_parser_get_null_terminated_by_index((void*)(¶meters_.target), index); } -const uint8_t* argument_parser_get_listener() +const uint8_t* argument_parser_get_listener(void) { return buffer_uint8_t_data((void*)(¶meters_.listener), 0); } -void argument_parser_release() +void argument_parser_release(void) { if (is_init) { diff --git a/argument_parser.h b/argument_parser.h index 8693b36..ac10091 100644 --- a/argument_parser.h +++ b/argument_parser.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2020, 2022 TheVice + * Copyright (c) 2019 - 2020, 2022, 2024 TheVice * */ @@ -28,26 +28,26 @@ uint8_t argument_from_char( const char* input_start, const char* input_finish, void* output, int* argc, char*** argv); -uint8_t argument_parser_init(); +uint8_t argument_parser_init(void); -uint8_t argument_parser_get_debug(); -uint8_t argument_parser_get_indent(); -uint8_t argument_parser_get_module_priority(); -uint8_t argument_parser_get_no_logo(); -uint8_t argument_parser_get_pause(); -uint8_t argument_parser_get_program_help(); -uint8_t argument_parser_get_project_help(); -uint8_t argument_parser_get_quiet(); -uint8_t argument_parser_get_verbose(); -uint16_t argument_parser_get_encoding(); +uint8_t argument_parser_get_debug(void); +uint8_t argument_parser_get_indent(void); +uint8_t argument_parser_get_module_priority(void); +uint8_t argument_parser_get_no_logo(void); +uint8_t argument_parser_get_pause(void); +uint8_t argument_parser_get_program_help(void); +uint8_t argument_parser_get_project_help(void); +uint8_t argument_parser_get_quiet(void); +uint8_t argument_parser_get_verbose(void); +uint16_t argument_parser_get_encoding(void); -const void* argument_parser_get_properties(); +const void* argument_parser_get_properties(void); const uint8_t* argument_parser_get_build_file(int index); -const uint8_t* argument_parser_get_log_file(); +const uint8_t* argument_parser_get_log_file(void); const uint8_t* argument_parser_get_target(int index); -const uint8_t* argument_parser_get_listener(); +const uint8_t* argument_parser_get_listener(void); -void argument_parser_release(); +void argument_parser_release(void); #endif diff --git a/bit_converter.c b/bit_converter.c index 93b2759..f7bacbc 100644 --- a/bit_converter.c +++ b/bit_converter.c @@ -43,7 +43,7 @@ \ return 1; -uint8_t bit_converter_is_little_endian() +uint8_t bit_converter_is_little_endian(void) { union endian_union { diff --git a/bit_converter.h b/bit_converter.h index 31cda60..9364b93 100644 --- a/bit_converter.h +++ b/bit_converter.h @@ -10,7 +10,7 @@ #include -uint8_t bit_converter_is_little_endian(); +uint8_t bit_converter_is_little_endian(void); uint8_t bit_converter_get_bytes_from_uint16_t(uint16_t input, uint8_t* output); uint8_t bit_converter_get_bytes_from_uint32_t(uint32_t input, uint8_t* output); diff --git a/buffer.c b/buffer.c index 4d5d52a..2c4dda1 100644 --- a/buffer.c +++ b/buffer.c @@ -64,7 +64,7 @@ struct buffer* buffer_to_real_buffer(const void* the_buffer) return (struct buffer*)real_buffer; } -uint8_t buffer_size_of() +uint8_t buffer_size_of(void) { return (uint8_t)sizeof(struct buffer); } @@ -283,6 +283,19 @@ void* buffer_data(const void* the_buffer_, ptrdiff_t index) return (void*)((uint8_t*)the_buffer->data + index); } +void* buffer_data_finish(const void* the_buffer_) +{ + const struct buffer* the_buffer = (const struct buffer*)the_buffer_; + + if (NULL == the_buffer || + NULL == the_buffer->data) + { + return NULL; + } + + return (void*)((uint8_t*)the_buffer->data + the_buffer->size); +} + char* buffer_char_data(const void* the_buffer, ptrdiff_t data_position) { return (char*)buffer_data(the_buffer, sizeof(char) * data_position); @@ -432,7 +445,7 @@ uint8_t buffer_return_to_pool(void* the_buffer) return 1; } -uint8_t buffer_release_pool() +uint8_t buffer_release_pool(void) { if (is_pool_init) { diff --git a/buffer.h b/buffer.h index 77a75f9..c633228 100644 --- a/buffer.h +++ b/buffer.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019, 2022 TheVice + * Copyright (c) 2019, 2022, 2024 TheVice * */ @@ -14,7 +14,7 @@ #define BUFFER_SIZE_OF (2 * sizeof(ptrdiff_t) + sizeof(void*)) -uint8_t buffer_size_of(); +uint8_t buffer_size_of(void); uint8_t buffer_init(void* the_buffer, uint8_t size_of_buffer); @@ -32,6 +32,7 @@ uint8_t buffer_append_buffer(void* the_buffer, const void* data, ptrdiff_t data_ uint8_t buffer_append_data_from_buffer(void* the_buffer, const void* the_source_buffer); void* buffer_data(const void* the_buffer, ptrdiff_t index); +void* buffer_data_finish(const void* the_buffer); char* buffer_char_data(const void* the_buffer, ptrdiff_t data_position); uint8_t* buffer_uint8_t_data(const void* the_buffer, ptrdiff_t data_position); wchar_t* buffer_wchar_t_data(const void* the_buffer, ptrdiff_t data_position); @@ -47,6 +48,6 @@ uint8_t buffer_shrink_to_fit(void* the_buffer); uint8_t buffer_init_pool(void** the_buffer); uint8_t buffer_return_to_pool(void* the_buffer); -uint8_t buffer_release_pool(); +uint8_t buffer_release_pool(void); #endif diff --git a/common.c b/common.c index 3761376..521a11c 100644 --- a/common.c +++ b/common.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -220,22 +220,22 @@ void common_set_error_output_stream(void* stream) error_output_stream = stream; } -void* common_get_output_stream() +void* common_get_output_stream(void) { return NULL == output_stream ? stdout : output_stream; } -void* common_get_error_output_stream() +void* common_get_error_output_stream(void) { return NULL == error_output_stream ? stderr : error_output_stream; } -uint8_t common_is_output_stream_standard() +uint8_t common_is_output_stream_standard(void) { return NULL == output_stream; } -uint8_t common_is_error_output_stream_standard() +uint8_t common_is_error_output_stream_standard(void) { return NULL == error_output_stream; } @@ -247,7 +247,7 @@ void common_set_module_priority(uint8_t priority) module_priority = 0 < priority; } -uint8_t common_get_module_priority() +uint8_t common_get_module_priority(void) { return module_priority; } diff --git a/common.h b/common.h index 3f5f3fc..b658db6 100644 --- a/common.h +++ b/common.h @@ -46,13 +46,13 @@ uint8_t common_get_attributes_and_arguments_for_task( void common_set_output_stream(void* stream); void common_set_error_output_stream(void* stream); -void* common_get_output_stream(); -void* common_get_error_output_stream(); -uint8_t common_is_output_stream_standard(); -uint8_t common_is_error_output_stream_standard(); +void* common_get_output_stream(void); +void* common_get_error_output_stream(void); +uint8_t common_is_output_stream_standard(void); +uint8_t common_is_error_output_stream_standard(void); void common_set_module_priority(uint8_t priority); -uint8_t common_get_module_priority(); +uint8_t common_get_module_priority(void); const uint8_t* common_get_string_at( const uint8_t* start, const uint8_t* finish, diff --git a/date_time.c b/date_time.c index 483cef5..9a3072c 100644 --- a/date_time.c +++ b/date_time.c @@ -485,7 +485,7 @@ uint8_t datetime_is_leap_year(uint32_t year) return ((!(year % 400)) || ((year % 100) && (!(year % 4)))); } -int64_t datetime_ticks() +int64_t datetime_ticks(void) { const clock_t ticks = clock(); @@ -497,7 +497,7 @@ int64_t datetime_ticks() return ticks; } -int64_t datetime_now_utc() +int64_t datetime_now_utc(void) { time_t now = 0; @@ -515,7 +515,7 @@ int64_t datetime_now_utc() (uint8_t)tm_u->tm_hour, (uint8_t)tm_u->tm_min, (uint8_t)tm_u->tm_sec); } -int64_t datetime_now() +int64_t datetime_now(void) { time_t now = 0; @@ -634,7 +634,7 @@ uint8_t datetime_decode( return 1; } #if !defined(_WIN32) -long datetime_get_bias() +long datetime_get_bias(void) { time_t now = 0; diff --git a/date_time.h b/date_time.h index 5cabbd9..6658ecf 100644 --- a/date_time.h +++ b/date_time.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -40,9 +40,9 @@ uint32_t datetime_get_year(int64_t input); uint8_t datetime_is_leap_year(uint32_t year); -int64_t datetime_ticks(); -int64_t datetime_now_utc(); -int64_t datetime_now(); +int64_t datetime_ticks(void); +int64_t datetime_now_utc(void); +int64_t datetime_now(void); int64_t datetime_encode( uint32_t year, uint8_t month, uint8_t day, @@ -52,7 +52,7 @@ uint8_t datetime_decode( uint8_t* hour, uint8_t* minute, uint8_t* second, uint16_t* year_day); #if !defined(_WIN32) -long datetime_get_bias(); +long datetime_get_bias(void); #endif int64_t date_time_millisecond_to_second(uint64_t millisecond); diff --git a/environment.c b/environment.c index 98989d3..4efeede 100644 --- a/environment.c +++ b/environment.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -318,6 +318,41 @@ uint8_t environment_get_folder_path(enum SpecialFolder folder, void* path) return common_append_string_to_buffer((const uint8_t*)user_info->pw_dir, path); } + case Programs: + case Favorites: + case Startup: + case Recent: + case SendTo: + case StartMenu: + case MyComputer: + case NetworkShortcuts: + case Fonts: + case CommonStartMenu: + case CommonPrograms: + case CommonStartup: + case CommonDesktopDirectory: + case PrinterShortcuts: + case InternetCache: + case Cookies: + case History: + case Windows: + case System: + case ProgramFiles: + case SystemX86: + case ProgramFilesX86: + case CommonProgramFiles: + case CommonProgramFilesX86: + case CommonTemplates: + case CommonDocuments: + case CommonAdminTools: + case AdminTools: + case CommonMusic: + case CommonPictures: + case CommonVideos: + case Resources: + case LocalizedResources: + case CommonOemLinks: + case CDBurning: default: break; } @@ -467,7 +502,7 @@ uint8_t environment_get_windows_version(void* version) #if defined(_MSC_VER) && (_MSC_VER >= 1800) #else -uint8_t IsWindowsServer() +uint8_t IsWindowsServer(void) { OSVERSIONINFOEXW osvi; memset(&osvi, 0, sizeof(OSVERSIONINFOEXW)); @@ -483,7 +518,7 @@ uint8_t IsWindowsServer() static uint8_t operating_system[UINT8_MAX]; static uint8_t is_data_of_operating_system_filled = 0; -const void* environment_get_operating_system() +const void* environment_get_operating_system(void) { if (!is_data_of_operating_system_filled) { @@ -512,7 +547,7 @@ const void* environment_get_operating_system() static uint8_t operating_system[sizeof(struct utsname) + INT8_MAX]; static uint8_t is_data_of_operating_system_filled = 0; -const void* environment_get_operating_system() +const void* environment_get_operating_system(void) { if (!is_data_of_operating_system_filled) { @@ -791,7 +826,7 @@ uint8_t environment_variable_exists(const uint8_t* variable_name_start, const ui return environment_get_variable(variable_name_start, variable_name_finish, NULL); } -uint8_t environment_is64bit_process() +uint8_t environment_is64bit_process(void) { #if defined(_WIN64) || defined(__amd64) || defined(__x86_64) || defined(__aarch64__) return 1; @@ -800,7 +835,7 @@ uint8_t environment_is64bit_process() #endif } -uint8_t environment_is64bit_operating_system() +uint8_t environment_is64bit_operating_system(void) { #if defined(_WIN64) || defined(__amd64) || defined(__x86_64) || defined(__aarch64__) return 1; @@ -870,7 +905,7 @@ uint8_t environment_is64bit_operating_system() #endif } -uint16_t environment_processor_count() +uint16_t environment_processor_count(void) { #if defined(_WIN32) SYSTEM_INFO system_info; diff --git a/environment.h b/environment.h index 58c63da..99a04a2 100644 --- a/environment.h +++ b/environment.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -75,15 +75,15 @@ enum SpecialFolder uint8_t environment_get_folder_path(enum SpecialFolder folder, void* path); uint8_t environment_get_machine_name(void* name); -const void* environment_get_operating_system(); +const void* environment_get_operating_system(void); uint8_t environment_get_user_name(void* name); uint8_t environment_get_variable( const uint8_t* variable_name_start, const uint8_t* variable_name_finish, void* variable); uint8_t environment_newline(void* newline); uint8_t environment_variable_exists( const uint8_t* variable_name_start, const uint8_t* variable_name_finish); -uint8_t environment_is64bit_process(); -uint8_t environment_is64bit_operating_system(); -uint16_t environment_processor_count(); +uint8_t environment_is64bit_process(void); +uint8_t environment_is64bit_operating_system(void); +uint16_t environment_processor_count(void); #endif diff --git a/exec.c b/exec.c index 697a207..d453abd 100644 --- a/exec.c +++ b/exec.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -679,12 +679,15 @@ uint8_t exec_posix_with_redirect( close(file_des[0]); count = 0; + int count_ = 0; - if (-1 == wait((int*)&count)) + if (-1 == wait(&count_)) { return 0; } + count = (ssize_t)count_; + if (NULL != result_property) { return property_set_by_pointer( diff --git a/file_system.c b/file_system.c index 9703268..2c27c6c 100644 --- a/file_system.c +++ b/file_system.c @@ -1023,7 +1023,7 @@ int64_t file_system_datetime_to_win32_time(int64_t input) (O).dwHighDateTime = (I) >> 32; \ (O).dwLowDateTime = (int32_t)(I);/* && INT32_MAX;*/ -long file_system_get_bias() +long file_system_get_bias(void) { static uint8_t loaded = 0; static long result = 0; diff --git a/interpreter.c b/interpreter.c index 676cab8..c53aa04 100644 --- a/interpreter.c +++ b/interpreter.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -2029,7 +2029,7 @@ uint8_t interpreter_evaluate_tasks( return returned; } -uint8_t interpreter_get_unknown_task_id() +uint8_t interpreter_get_unknown_task_id(void) { return UNKNOWN_TASK; } diff --git a/interpreter.file_system.c b/interpreter.file_system.c index 1c5ff8e..e7ee4f7 100644 --- a/interpreter.file_system.c +++ b/interpreter.file_system.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2021 - 2022 TheVice + * Copyright (c) 2021 - 2022, 2024 TheVice * */ @@ -63,52 +63,52 @@ enum enumerate_entry_types UNKNOWN_ENTRY_TYPE }; -uint8_t file_get_id_of_file_set_creation_time_function() +uint8_t file_get_id_of_file_set_creation_time_function(void) { return file_set_creation_time_; } -uint8_t file_get_id_of_file_set_creation_time_utc_function() +uint8_t file_get_id_of_file_set_creation_time_utc_function(void) { return file_set_creation_time_utc_; } -uint8_t file_get_id_of_file_set_last_access_time_function() +uint8_t file_get_id_of_file_set_last_access_time_function(void) { return file_set_last_access_time_; } -uint8_t file_get_id_of_file_set_last_access_time_utc_function() +uint8_t file_get_id_of_file_set_last_access_time_utc_function(void) { return file_set_last_access_time_utc_; } -uint8_t file_get_id_of_file_set_last_write_time_function() +uint8_t file_get_id_of_file_set_last_write_time_function(void) { return file_set_last_write_time_; } -uint8_t file_get_id_of_file_set_last_write_time_utc_function() +uint8_t file_get_id_of_file_set_last_write_time_utc_function(void) { return file_set_last_write_time_utc_; } -uint8_t dir_get_id_of_get_current_directory_function() +uint8_t dir_get_id_of_get_current_directory_function(void) { return get_current_directory; } -uint8_t file_system_get_id_of_directory_entry() +uint8_t file_system_get_id_of_directory_entry(void) { return directory_entry; } -uint8_t file_system_get_id_of_file_entry() +uint8_t file_system_get_id_of_file_entry(void) { return file_entry; } -uint8_t file_system_get_id_of_all_entries() +uint8_t file_system_get_id_of_all_entries(void) { return all_entries; } diff --git a/interpreter.file_system.h b/interpreter.file_system.h index b7ec60c..b10980d 100644 --- a/interpreter.file_system.h +++ b/interpreter.file_system.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2021 - 2022 TheVice + * Copyright (c) 2021 - 2022, 2024 TheVice * */ @@ -10,18 +10,18 @@ #include -uint8_t file_get_id_of_file_set_creation_time_function(); -uint8_t file_get_id_of_file_set_creation_time_utc_function(); -uint8_t file_get_id_of_file_set_last_access_time_function(); -uint8_t file_get_id_of_file_set_last_access_time_utc_function(); -uint8_t file_get_id_of_file_set_last_write_time_function(); -uint8_t file_get_id_of_file_set_last_write_time_utc_function(); +uint8_t file_get_id_of_file_set_creation_time_function(void); +uint8_t file_get_id_of_file_set_creation_time_utc_function(void); +uint8_t file_get_id_of_file_set_last_access_time_function(void); +uint8_t file_get_id_of_file_set_last_access_time_utc_function(void); +uint8_t file_get_id_of_file_set_last_write_time_function(void); +uint8_t file_get_id_of_file_set_last_write_time_utc_function(void); -uint8_t dir_get_id_of_get_current_directory_function(); +uint8_t dir_get_id_of_get_current_directory_function(void); -uint8_t file_system_get_id_of_directory_entry(); -uint8_t file_system_get_id_of_file_entry(); -uint8_t file_system_get_id_of_all_entries(); +uint8_t file_system_get_id_of_directory_entry(void); +uint8_t file_system_get_id_of_file_entry(void); +uint8_t file_system_get_id_of_all_entries(void); uint8_t dir_get_function( const uint8_t* name_start, const uint8_t* name_finish); diff --git a/interpreter.h b/interpreter.h index 7a0ac43..8d4f190 100644 --- a/interpreter.h +++ b/interpreter.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -84,7 +84,7 @@ uint8_t platform_exec_function( void* output); /*path*/ -uint8_t path_get_id_of_get_full_path_function(); +uint8_t path_get_id_of_get_full_path_function(void); uint8_t path_get_function( const uint8_t* name_start, const uint8_t* name_finish); uint8_t path_exec_function( @@ -185,6 +185,6 @@ uint8_t interpreter_evaluate_tasks( void* the_project, const void* the_target, const void* elements, const struct range* sub_nodes_names, uint8_t target_help, uint8_t verbose); -uint8_t interpreter_get_unknown_task_id(); +uint8_t interpreter_get_unknown_task_id(void); #endif diff --git a/interpreter.path.c b/interpreter.path.c index 75e1729..aafa050 100644 --- a/interpreter.path.c +++ b/interpreter.path.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2021 - 2022 TheVice + * Copyright (c) 2021 - 2022, 2024 TheVice * */ @@ -36,7 +36,7 @@ enum path_function UNKNOWN_PATH_FUNCTION }; -uint8_t path_get_id_of_get_full_path_function() +uint8_t path_get_id_of_get_full_path_function(void) { return path_get_full_path_function; } diff --git a/interpreter.property.c b/interpreter.property.c index 7b48c49..eaabd01 100644 --- a/interpreter.property.c +++ b/interpreter.property.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2022 TheVice + * Copyright (c) 2022, 2024 TheVice * */ @@ -125,7 +125,7 @@ enum property_function UNKNOWN_PROPERTY_FUNCTION }; -uint8_t property_get_id_of_get_value_function() +uint8_t property_get_id_of_get_value_function(void) { return property_get_value_function; } diff --git a/interpreter.property.h b/interpreter.property.h index 839a96f..43aed4d 100644 --- a/interpreter.property.h +++ b/interpreter.property.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2022 TheVice + * Copyright (c) 2022, 2024 TheVice * */ @@ -16,7 +16,7 @@ uint8_t property_get_attributes_and_arguments_for_task( uint8_t property_evaluate_task( void* the_project, void* properties, const void* task_arguments, uint8_t verbose); -uint8_t property_get_id_of_get_value_function(); +uint8_t property_get_id_of_get_value_function(void); uint8_t property_get_function(const uint8_t* name_start, const uint8_t* name_finish); uint8_t property_exec_function( const void* the_project, uint8_t function, const void* arguments, diff --git a/interpreter.string_unit.c b/interpreter.string_unit.c index 9e4dbab..399077f 100644 --- a/interpreter.string_unit.c +++ b/interpreter.string_unit.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2021 - 2022 TheVice + * Copyright (c) 2021 - 2022, 2024 TheVice * */ @@ -22,27 +22,27 @@ enum string_function UNKNOWN_STRING_FUNCTION }; -uint8_t string_get_id_of_to_lower_function() +uint8_t string_get_id_of_to_lower_function(void) { return to_lower; } -uint8_t string_get_id_of_to_upper_function() +uint8_t string_get_id_of_to_upper_function(void) { return to_upper; } -uint8_t string_get_id_of_trim_function() +uint8_t string_get_id_of_trim_function(void) { return trim; } -uint8_t string_get_id_of_trim_end_function() +uint8_t string_get_id_of_trim_end_function(void) { return trim_end; } -uint8_t string_get_id_of_trim_start_function() +uint8_t string_get_id_of_trim_start_function(void) { return trim_start; } diff --git a/interpreter.string_unit.h b/interpreter.string_unit.h index 10a57c3..d30d262 100644 --- a/interpreter.string_unit.h +++ b/interpreter.string_unit.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2021 - 2022 TheVice + * Copyright (c) 2021 - 2022, 2024 TheVice * */ @@ -10,11 +10,11 @@ #include -uint8_t string_get_id_of_to_lower_function(); -uint8_t string_get_id_of_to_upper_function(); -uint8_t string_get_id_of_trim_function(); -uint8_t string_get_id_of_trim_end_function(); -uint8_t string_get_id_of_trim_start_function(); +uint8_t string_get_id_of_to_lower_function(void); +uint8_t string_get_id_of_to_upper_function(void); +uint8_t string_get_id_of_trim_function(void); +uint8_t string_get_id_of_trim_end_function(void); +uint8_t string_get_id_of_trim_start_function(void); uint8_t string_get_function( const uint8_t* name_start, const uint8_t* name_finish); uint8_t string_exec_function( diff --git a/load_file.c b/load_file.c index 9e63cfd..993522c 100644 --- a/load_file.c +++ b/load_file.c @@ -12,7 +12,7 @@ #include "range.h" #include "text_encoding.h" -#define READ_WITH_ENCODING_FROM_BOM_AND_CONVERT_TO_UTF(FILE_, START, FINISH, SIZE, USE_OFFSET, TYPE, OUTPUT, CONVERTER) \ +#define READ_WITH_ENCODING_FROM_BOM_AND_CONVERT_TO_UTF(FILE_, START, FINISH, SIZE, USE_OFFSET, ENCODING, OUTPUT) \ if (!buffer_resize((OUTPUT), sizeof(uint64_t)) || \ !file_read_with_several_steps((FILE_), (OUTPUT))) \ { \ @@ -56,14 +56,14 @@ } \ \ if (!buffer_resize((OUTPUT), 0) || \ - ((START) < (FINISH) && !CONVERTER((const TYPE*)(START), (const TYPE*)(FINISH), (OUTPUT)))) \ + ((START) < (FINISH) && !text_encoding_UTF_to_UTF8((START), (FINISH), (ENCODING), (OUTPUT)))) \ { \ return 0; \ } -#define READ_WITH_ENCODING_FROM_ARGUMENT_AND_CONVERT_TO_UTF(START, FINISH, OUTPUT, SIZE, FILE_, CONVERTER, TYPE) \ +#define READ_WITH_ENCODING_FROM_ARGUMENT_AND_CONVERT_TO_UTF(START, FINISH, OUTPUT, SIZE, FILE_, ENCODING, TYPE) \ (START) = buffer_uint8_t_data((OUTPUT), 0); \ - (FINISH) = buffer_uint8_t_data((OUTPUT), 0) + 2 * sizeof(uint64_t) - 1; \ + (FINISH) = buffer_uint8_t_data((OUTPUT), 0) + 2 * sizeof(uint64_t) - 1; \ \ for ((SIZE) = buffer_size(OUTPUT); 0 < (SIZE); --(SIZE)) \ {\ @@ -97,7 +97,7 @@ (FINISH) = buffer_uint8_t_data((OUTPUT), 0) + sz; \ \ if (!buffer_resize((OUTPUT), 0) || \ - !CONVERTER((const TYPE*)(START), (const TYPE*)(FINISH), (OUTPUT))) \ + !text_encoding_UTF_to_UTF8((START), (FINISH), (ENCODING), (OUTPUT))) \ { \ return 0; \ } \ @@ -240,26 +240,22 @@ uint8_t load_file(const uint8_t* path, uint16_t encoding, void* output, uint8_t case UTF16BE: READ_WITH_ENCODING_FROM_BOM_AND_CONVERT_TO_UTF( - file, data, path, readded, use_offset, uint16_t, output, - text_encoding_UTF16BE_to_UTF8); + file, data, path, readded, use_offset, UTF16BE, output); return 1; case UTF16LE: READ_WITH_ENCODING_FROM_BOM_AND_CONVERT_TO_UTF( - file, data, path, readded, use_offset, uint16_t, output, - text_encoding_UTF16LE_to_UTF8); + file, data, path, readded, use_offset, UTF16LE, output); return 1; case UTF32BE: READ_WITH_ENCODING_FROM_BOM_AND_CONVERT_TO_UTF( - file, data, path, readded, use_offset, uint32_t, output, - text_encoding_UTF32BE_to_UTF8); + file, data, path, readded, use_offset, UTF32BE, output); return 1; case UTF32LE: READ_WITH_ENCODING_FROM_BOM_AND_CONVERT_TO_UTF( - file, data, path, readded, use_offset, uint32_t, output, - text_encoding_encode_UTF8); + file, data, path, readded, use_offset, UTF32LE, output); return 1; default: @@ -279,73 +275,81 @@ uint8_t load_file(const uint8_t* path, uint16_t encoding, void* output, uint8_t case BigEndianUnicode: case UTF16BE: - READ_WITH_ENCODING_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, - text_encoding_UTF16BE_to_UTF8, uint16_t); + READ_WITH_ENCODING_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, UTF16BE, uint16_t); return 1; case Unicode: case UTF16LE: - READ_WITH_ENCODING_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, - text_encoding_UTF16LE_to_UTF8, uint16_t); + READ_WITH_ENCODING_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, UTF16LE, uint16_t); return 1; case UTF32BE: - READ_WITH_ENCODING_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, - text_encoding_UTF32BE_to_UTF8, uint32_t); + READ_WITH_ENCODING_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, UTF32BE, uint32_t); return 1; case UTF32: case UTF32LE: - READ_WITH_ENCODING_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, - text_encoding_encode_UTF8, uint32_t); + READ_WITH_ENCODING_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, UTF32LE, uint32_t); return 1; case Windows_874: case ISO_8859_11: - READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, - text_encoding_UTF8_from_code_page, Windows_874, uint8_t); + READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, + text_encoding_UTF8_from_code_page, Windows_874, uint8_t); return 1; case Windows_1250: case ISO_8859_2:/*TODO:161...190*/ - READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, - text_encoding_UTF8_from_code_page, Windows_1250, uint8_t); + READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, + text_encoding_UTF8_from_code_page, Windows_1250, uint8_t); return 1; case Windows_1251: case Windows_1255: case Windows_1256: case Windows_1258: - READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, - text_encoding_UTF8_from_code_page, encoding, uint8_t); + READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, + text_encoding_UTF8_from_code_page, encoding, uint8_t); return 1; case Windows_1252: case ISO_8859_1: - READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, - text_encoding_UTF8_from_code_page, Windows_1252, uint8_t); + READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, + text_encoding_UTF8_from_code_page, Windows_1252, uint8_t); return 1; case Windows_1253: case ISO_8859_7: - READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, - text_encoding_UTF8_from_code_page, Windows_1253, uint8_t); + READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, + text_encoding_UTF8_from_code_page, Windows_1253, uint8_t); return 1; case Windows_1254: case ISO_8859_9: - READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, - text_encoding_UTF8_from_code_page, Windows_1254, uint8_t); + READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, + text_encoding_UTF8_from_code_page, Windows_1254, uint8_t); return 1; case Windows_1257: case ISO_8859_13:/*TODO:...*/ - READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, - text_encoding_UTF8_from_code_page, Windows_1257, uint8_t); + READ_WITH_CODE_PAGE_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, + text_encoding_UTF8_from_code_page, Windows_1257, uint8_t); return 1; case ASCII: - READ_AS_ASCII_FROM_ARGUMENT_AND_CONVERT_TO_UTF(path, data, output, readded, file, UTF8); + READ_AS_ASCII_FROM_ARGUMENT_AND_CONVERT_TO_UTF( + path, data, output, readded, file, UTF8); return 1; default: diff --git a/load_tasks.c b/load_tasks.c index 46332ad..01e4292 100644 --- a/load_tasks.c +++ b/load_tasks.c @@ -91,7 +91,7 @@ typedef uint8_t(*evaluate_task)(const uint8_t* task, typedef uint8_t(*evaluate_function)(const uint8_t* function, const uint8_t** values, const uint16_t* values_lengths, uint8_t values_count, const uint8_t** output, uint16_t* output_length); -typedef void (*module_release)(); +typedef void (*module_release)(void); struct name_space_in_module { @@ -538,13 +538,15 @@ uint8_t load_tasks_evaluate_loaded_task( } else { + static uint16_t task_attributes_count_ = 0; + if (!buffer_resize(task_arguments, 2 * sizeof(uint8_t**))) { return 0; } arguments = (const uint8_t**)buffer_data(task_arguments, 0); - arguments_lengths = (uint16_t*)&task_attributes_count; + arguments_lengths = &task_attributes_count_; if (!buffer_resize(task_arguments, 0)) { @@ -626,8 +628,11 @@ uint8_t load_tasks_evaluate_loaded_function(const void* the_module, const uint8_ } else { - values = (const uint8_t**)&arguments_count; - values_lengths = (uint16_t*)&arguments_count; + static const uint8_t value_ = 0; + static const uint8_t* values_ = &value_; + static uint16_t values_lengths_ = 0; + values = &values_; + values_lengths = &values_lengths_; } const uint8_t* output = NULL; diff --git a/operating_system.c b/operating_system.c index fafce94..a7d429e 100644 --- a/operating_system.c +++ b/operating_system.c @@ -276,28 +276,28 @@ const uint8_t* operating_system_get_platform_name(const void* os) return IDs_str[count]; } -const uint8_t* platform_get_name() +const uint8_t* platform_get_name(void) { return operating_system_get_platform_name(environment_get_operating_system()); } -uint8_t platform_is_macos() +uint8_t platform_is_macos(void) { return macOS == operating_system_get_platform(environment_get_operating_system()); } -uint8_t platform_is_unix() +uint8_t platform_is_unix(void) { const enum PlatformID platformID = operating_system_get_platform(environment_get_operating_system()); return Unix == platformID || macOS == platformID; } -uint8_t platform_is_windows() +uint8_t platform_is_windows(void) { return Win32 == operating_system_get_platform(environment_get_operating_system()); } -uint8_t platform_is_windows_server() +uint8_t platform_is_windows_server(void) { #if defined(_WIN32) const struct OperatingSystem* os = (const struct OperatingSystem*)environment_get_operating_system(); diff --git a/operating_system.h b/operating_system.h index 2ccb887..7e3db52 100644 --- a/operating_system.h +++ b/operating_system.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -42,10 +42,10 @@ const uint8_t* operating_system_to_string(const void* os); uint8_t operating_system_is_windows_server(const void* os); const uint8_t* operating_system_get_platform_name(const void* os); -const uint8_t* platform_get_name(); -uint8_t platform_is_macos(); -uint8_t platform_is_unix(); -uint8_t platform_is_windows(); -uint8_t platform_is_windows_server(); +const uint8_t* platform_get_name(void); +uint8_t platform_is_macos(void); +uint8_t platform_is_unix(void); +uint8_t platform_is_windows(void); +uint8_t platform_is_windows_server(void); #endif diff --git a/path.c b/path.c index a7bc1a8..13d3430 100644 --- a/path.c +++ b/path.c @@ -721,7 +721,7 @@ uint8_t path_get_temp_file_name(void* temp_file_name) return 0; } - wchar_t* prefix_string = L"file"; + const wchar_t* prefix_string = L"file"; static const UINT unique = 0; if (unique == GetTempFileNameW(path_name, prefix_string, unique, temp_file_name_)) diff --git a/property.c b/property.c index 4cdc07e..37abf5f 100644 --- a/property.c +++ b/property.c @@ -220,7 +220,7 @@ uint8_t property_set_by_name( uint8_t dynamic, uint8_t over_write, uint8_t read_only, uint8_t verbose) { - struct property* prop = NULL; + void* prop = NULL; if (NULL == properties || !property_is_name_valid(name, name_length) || @@ -229,7 +229,7 @@ uint8_t property_set_by_name( return 0; } - if (property_exists(properties, name, name_length, (void**)&prop)) + if (property_exists(properties, name, name_length, &prop)) { if (!over_write) { diff --git a/sleep_unit.c b/sleep_unit.c index cc799db..33b63cb 100644 --- a/sleep_unit.c +++ b/sleep_unit.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2020 - 2021 TheVice + * Copyright (c) 2020 - 2021, 2024 TheVice * */ @@ -20,6 +20,6 @@ uint8_t sleep_for(uint32_t milliseconds) #if defined(_WIN32) return 0 == SleepEx(milliseconds, FALSE); #else - return 0 == sleep(date_time_millisecond_to_second(milliseconds)); + return 0 == sleep((uint32_t)date_time_millisecond_to_second(milliseconds)); #endif } diff --git a/tests.cmake b/tests.cmake index eb9d0ac..1bb26aa 100644 --- a/tests.cmake +++ b/tests.cmake @@ -5,8 +5,8 @@ add_executable(tests_exec_app ) target_compile_options(tests_exec_app PRIVATE - $<$:-Wall -Wextra -Werror> - $<$:-Wall -Wextra -Werror> + $<$:-Wall -Wextra -Werror -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wstrict-prototypes -Wundef> + $<$:-Wall -Wextra -Werror -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wstrict-prototypes -Wundef> $<$:/W4 /WX> ) @@ -50,8 +50,8 @@ add_executable(ant4c_tests ) target_compile_options(ant4c_tests PRIVATE - $<$:-Wall -Wextra -Werror> - $<$:-Wall -Wextra -Werror> + $<$:-Wall -Wextra -Werror -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wundef> + $<$:-Wall -Wextra -Werror -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wundef> $<$:/W4 /WX> ) diff --git a/tests.xml b/tests.xml index b09c937..95b9f44 100644 --- a/tests.xml +++ b/tests.xml @@ -10841,6 +10841,131 @@ Approximate round trip times in milli-seconds: 2 65023 + + UTF7 + + + 0x00 + UTF7 + + + 0x00 0x01 0x02 + UTF8 + 1 + 0x00 0x01 0x02 + + + 0x00 0x54 0x00 0x68 0x00 0x65 0x00 0x20 + 0x00 0x71 0x00 0x75 0x00 0x69 0x00 0x63 + 0x00 0x6B 0x00 0x20 0x00 0x62 0x00 0x72 + 0x00 0x6F 0x00 0x77 0x00 0x6E 0x00 0x20 + 0x00 0x66 0x00 0x6F 0x00 0x78 0x00 0x20 + 0x00 0x6A 0x00 0x75 0x00 0x6D 0x00 0x70 + 0x00 0x73 0x00 0x20 0x00 0x6F 0x00 0x76 + 0x00 0x65 0x00 0x72 0x00 0x20 0x00 0x74 + 0x00 0x68 0x00 0x65 0x00 0x20 0x00 0x6C + 0x00 0x61 0x00 0x7A 0x00 0x79 0x00 0x20 + 0x00 0x64 0x00 0x6F 0x00 0x67 0x00 0x2E + UTF16BE + 1 + 0x54 0x68 0x65 0x20 0x71 0x75 0x69 0x63 + 0x6B 0x20 0x62 0x72 0x6F 0x77 0x6E 0x20 + 0x66 0x6F 0x78 0x20 0x6A 0x75 0x6D 0x70 + 0x73 0x20 0x6F 0x76 0x65 0x72 0x20 0x74 + 0x68 0x65 0x20 0x6C 0x61 0x7A 0x79 0x20 + 0x64 0x6F 0x67 0x2E + + + 0x54 0x00 0x68 0x00 0x65 0x00 0x20 0x00 + 0x71 0x00 0x75 0x00 0x69 0x00 0x63 0x00 + 0x6B 0x00 0x20 0x00 0x62 0x00 0x72 0x00 + 0x6F 0x00 0x77 0x00 0x6E 0x00 0x20 0x00 + 0x66 0x00 0x6F 0x00 0x78 0x00 0x20 0x00 + 0x6A 0x00 0x75 0x00 0x6D 0x00 0x70 0x00 + 0x73 0x00 0x20 0x00 0x6F 0x00 0x76 0x00 + 0x65 0x00 0x72 0x00 0x20 0x00 0x74 0x00 + 0x68 0x00 0x65 0x00 0x20 0x00 0x6C 0x00 + 0x61 0x00 0x7A 0x00 0x79 0x00 0x20 0x00 + 0x64 0x00 0x6F 0x00 0x67 0x00 0x2E 0x00 + UTF16LE + 1 + 0x54 0x68 0x65 0x20 0x71 0x75 0x69 0x63 + 0x6B 0x20 0x62 0x72 0x6F 0x77 0x6E 0x20 + 0x66 0x6F 0x78 0x20 0x6A 0x75 0x6D 0x70 + 0x73 0x20 0x6F 0x76 0x65 0x72 0x20 0x74 + 0x68 0x65 0x20 0x6C 0x61 0x7A 0x79 0x20 + 0x64 0x6F 0x67 0x2E + + + 0x00 0x00 0x00 0x54 0x00 0x00 0x00 0x68 + 0x00 0x00 0x00 0x65 0x00 0x00 0x00 0x20 + 0x00 0x00 0x00 0x71 0x00 0x00 0x00 0x75 + 0x00 0x00 0x00 0x69 0x00 0x00 0x00 0x63 + 0x00 0x00 0x00 0x6B 0x00 0x00 0x00 0x20 + 0x00 0x00 0x00 0x62 0x00 0x00 0x00 0x72 + 0x00 0x00 0x00 0x6F 0x00 0x00 0x00 0x77 + 0x00 0x00 0x00 0x6E 0x00 0x00 0x00 0x20 + 0x00 0x00 0x00 0x66 0x00 0x00 0x00 0x6F + 0x00 0x00 0x00 0x78 0x00 0x00 0x00 0x20 + 0x00 0x00 0x00 0x6A 0x00 0x00 0x00 0x75 + 0x00 0x00 0x00 0x6D 0x00 0x00 0x00 0x70 + 0x00 0x00 0x00 0x73 0x00 0x00 0x00 0x20 + 0x00 0x00 0x00 0x6F 0x00 0x00 0x00 0x76 + 0x00 0x00 0x00 0x65 0x00 0x00 0x00 0x72 + 0x00 0x00 0x00 0x20 0x00 0x00 0x00 0x74 + 0x00 0x00 0x00 0x68 0x00 0x00 0x00 0x65 + 0x00 0x00 0x00 0x20 0x00 0x00 0x00 0x6C + 0x00 0x00 0x00 0x61 0x00 0x00 0x00 0x7A + 0x00 0x00 0x00 0x79 0x00 0x00 0x00 0x20 + 0x00 0x00 0x00 0x64 0x00 0x00 0x00 0x6F + 0x00 0x00 0x00 0x67 0x00 0x00 0x00 0x2E + UTF32BE + 1 + 0x54 0x68 0x65 0x20 0x71 0x75 0x69 0x63 + 0x6B 0x20 0x62 0x72 0x6F 0x77 0x6E 0x20 + 0x66 0x6F 0x78 0x20 0x6A 0x75 0x6D 0x70 + 0x73 0x20 0x6F 0x76 0x65 0x72 0x20 0x74 + 0x68 0x65 0x20 0x6C 0x61 0x7A 0x79 0x20 + 0x64 0x6F 0x67 0x2E + + + 0x54 0x00 0x00 0x00 0x68 0x00 0x00 0x00 + 0x65 0x00 0x00 0x00 0x20 0x00 0x00 0x00 + 0x71 0x00 0x00 0x00 0x75 0x00 0x00 0x00 + 0x69 0x00 0x00 0x00 0x63 0x00 0x00 0x00 + 0x6B 0x00 0x00 0x00 0x20 0x00 0x00 0x00 + 0x62 0x00 0x00 0x00 0x72 0x00 0x00 0x00 + 0x6F 0x00 0x00 0x00 0x77 0x00 0x00 0x00 + 0x6E 0x00 0x00 0x00 0x20 0x00 0x00 0x00 + 0x66 0x00 0x00 0x00 0x6F 0x00 0x00 0x00 + 0x78 0x00 0x00 0x00 0x20 0x00 0x00 0x00 + 0x6A 0x00 0x00 0x00 0x75 0x00 0x00 0x00 + 0x6D 0x00 0x00 0x00 0x70 0x00 0x00 0x00 + 0x73 0x00 0x00 0x00 0x20 0x00 0x00 0x00 + 0x6F 0x00 0x00 0x00 0x76 0x00 0x00 0x00 + 0x65 0x00 0x00 0x00 0x72 0x00 0x00 0x00 + 0x20 0x00 0x00 0x00 0x74 0x00 0x00 0x00 + 0x68 0x00 0x00 0x00 0x65 0x00 0x00 0x00 + 0x20 0x00 0x00 0x00 0x6C 0x00 0x00 0x00 + 0x61 0x00 0x00 0x00 0x7A 0x00 0x00 0x00 + 0x79 0x00 0x00 0x00 0x20 0x00 0x00 0x00 + 0x64 0x00 0x00 0x00 0x6F 0x00 0x00 0x00 + 0x67 0x00 0x00 0x00 0x2E 0x00 0x00 0x00 + UTF32LE + 1 + 0x54 0x68 0x65 0x20 0x71 0x75 0x69 0x63 + 0x6B 0x20 0x62 0x72 0x6F 0x77 0x6E 0x20 + 0x66 0x6F 0x78 0x20 0x6A 0x75 0x6D 0x70 + 0x73 0x20 0x6F 0x76 0x65 0x72 0x20 0x74 + 0x68 0x65 0x20 0x6C 0x61 0x7A 0x79 0x20 + 0x64 0x6F 0x67 0x2E + + + 0x30 0x53 0x74 0x30 0x30 0x2C 0x30 0x79 0x0A 0xD8 0x42 0xDF + UTF16LE + 1 + 0xE5 0x8C 0xB0 0xE3 0x81 0xB4 0xE2 0xB0 0xB0 0xE7 0xA4 0xB0 0xEF 0xBF 0xBD + diff --git a/tests_file_system.cpp b/tests_file_system.cpp index 89bc0ce..2fd35ea 100644 --- a/tests_file_system.cpp +++ b/tests_file_system.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -819,7 +819,7 @@ TEST(TestFileSystem_, file_set_attributes) { ASSERT_TRUE(file_set_attributes( path_, archive, hidden, normal, readonly, system_attribute)) << buffer_free(path); -#if TODO +#if defined(TODO) unsigned long attributes = 0; ASSERT_TRUE(file_get_attributes(path_, &attributes)) << buffer_free(path); // diff --git a/tests_text_encoding.cpp b/tests_text_encoding.cpp index 616be8d..9a37f94 100644 --- a/tests_text_encoding.cpp +++ b/tests_text_encoding.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -15,12 +15,14 @@ extern "C" { #include "text_encoding.h" } +#include #include #include #include #include #include #include +#include #include class TestTextEncoding : public TestsBaseXml @@ -1038,7 +1040,7 @@ TEST_F(TestTextEncoding, text_encoding_encode_UTF16) buffer_release(output); } -uint16_t fill_uint16_t(uint16_t max, uint16_t* result) +static uint16_t fill_uint16_t(uint16_t max, uint16_t* result) { if (nullptr == result) { @@ -1047,7 +1049,7 @@ uint16_t fill_uint16_t(uint16_t max, uint16_t* result) for (uint16_t i = 0, j = 0; i < max; ++i) { - if (127 < j) + if (INT8_MAX < j) { j = 0; } @@ -1115,5 +1117,83 @@ text_encoding_UTF8_to_UTF16BE text_encoding_UTF16BE_to_UTF8 text_encoding_UTF8_to_UTF32BE text_encoding_UTF32BE_to_UTF8 -text_encoding_get_one -*/ \ No newline at end of file +*/ + +TEST_F(TestTextEncoding, text_encoding_UTF_to_UTF8) +{ + std::string output_buffer(buffer_size_of(), 0); + auto output = reinterpret_cast(&output_buffer[0]); + ASSERT_TRUE(buffer_init(output, buffer_size_of())); + // + std::vector input; + std::vector expected_output; + + for (const auto& node : nodes) + { + const auto the_node = node.node(); + ASSERT_TRUE(buffer_resize(output, 0)) << buffer_free(output); + // + const auto input_hex(get_data_from_nodes(the_node, "input")); + input.clear(); + string_hex_parse(input_hex.c_str(), input); + // + const std::string encoding_str(the_node.select_node("encoding").node().child_value()); + const auto encoding_in_a_range(string_to_range(encoding_str)); + const auto encoding = text_encoding_get_one(encoding_in_a_range.start, encoding_in_a_range.finish); + ASSERT_NE(TEXT_ENCODING_UNKNOWN, encoding) << encoding_str << std::endl << buffer_free(output); + // + const auto output_hex(get_data_from_nodes(the_node, "output")); + expected_output.clear(); + string_hex_parse(output_hex.c_str(), expected_output); + // + const std::string return_str( + the_node.select_node("return").node().child_value()); + const auto return_in_a_range(string_to_range(return_str)); + const auto expected_return = + static_cast( + int_parse(return_in_a_range.start, return_in_a_range.finish)); + // + ASSERT_EQ(expected_return, text_encoding_UTF_to_UTF8( + input.data(), input.data() + input.size(), + encoding, output)) << input_hex << std::endl << buffer_free(output); + // + ASSERT_EQ(expected_output.size(), + static_cast(buffer_size(output))) << input_hex << std::endl << buffer_free(output); + const uint8_t* returned_output = buffer_uint8_t_data(output, 0); + + for (size_t i = 0, count = expected_output.size(); i < count; ++i, ++returned_output) + { + ASSERT_EQ(expected_output[i], *returned_output) + << input_hex << std::endl << i << std::endl << buffer_free(output); + } + + --node_count; + } + + buffer_release(output); +} + +TEST(TestTextEncoding_, text_encoding_get_one) +{ + static const std::map inputs = + { + std::make_pair("ASCII", ASCII), + std::make_pair("UTF7", UTF7), + std::make_pair("UTF8", UTF8), + std::make_pair("UTF16BE", UTF16BE), + std::make_pair("UTF16LE", UTF16LE), + std::make_pair("UTF32BE", UTF32BE), + std::make_pair("UTF32LE", UTF32LE), + std::make_pair("BigEndianUnicode", BigEndianUnicode), + std::make_pair("Unicode", Unicode), + std::make_pair("UTF32", UTF32), + std::make_pair("Default", Default), + std::make_pair("Unknown", TEXT_ENCODING_UNKNOWN), + }; + + for (const auto& input : inputs) + { + const auto input_in_a_range(string_to_range(std::get<0>(input))); + ASSERT_EQ(std::get<1>(input), text_encoding_get_one(input_in_a_range.start, input_in_a_range.finish)); + } +} diff --git a/text_encoding.c b/text_encoding.c index 46e73d3..9b8d62a 100644 --- a/text_encoding.c +++ b/text_encoding.c @@ -1,10 +1,14 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022, 2024 TheVice + * Copyright (c) 2019 - 2024 TheVice * */ +#ifndef NO_COMMON_UNIT +#include "stdc_secure_api.h" +#endif + #include "text_encoding.h" #ifndef NO_BUFFER_UNIT #include "buffer.h" @@ -256,8 +260,8 @@ uint8_t text_encoding_change_UTF32_endian(const uint32_t* input_start, const uin uint32_t* output); uint8_t text_encoding_decode_UTF32LE_single(const uint32_t* input_start, const uint32_t* input_finish, uint32_t* output); -#ifndef NO_BUFFER_UNIT -#define UTF_TO_ASCII(START, FINISH, SIZE, DECODE, TYPE, OUT, OUTPUT) \ +#if !defined(NO_BUFFER_UNIT) && !defined(NO_COMMON_UNIT) +#define UTF8_TO_ASCII(START, FINISH, SIZE, DECODE, TYPE, OUT, OUTPUT) \ while ((const TYPE*)(START) < (const TYPE*)(FINISH)) \ { \ (*(OUT)) = unknown_ASCII_char; \ @@ -285,6 +289,122 @@ uint8_t text_encoding_decode_UTF32LE_single(const uint32_t* input_start, const u START += (SIZE) * sizeof(TYPE); \ } +uint8_t text_encoding_UTF16_to_ASCII(const uint8_t* data_start, const uint8_t* data_finish, uint32_t* out, + uint8_t big_endian, void* output) +{ + while (data_start < data_finish) + { + static uint16_t data[2]; + ptrdiff_t size = data_finish - data_start; + *out = unknown_ASCII_char; + + if ((size_t)size < sizeof(uint16_t)) + { + return 0; + } + + if (big_endian) + { + if (2 * sizeof(uint16_t) <= (size_t)size) + { + MEM_CPY_C(data, data_start, 2 * sizeof(uint16_t)); + size = text_encoding_decode_UTF16BE_single(data, data + 2, out); + } + else + { + MEM_CPY_C(data, data_start, sizeof(uint16_t)); + size = text_encoding_decode_UTF16BE_single(data, data + 1, out); + } + } + else + { + if (2 * sizeof(uint16_t) <= (size_t)size) + { + MEM_CPY_C(data, data_start, 2 * sizeof(uint16_t)); + size = text_encoding_decode_UTF16LE_single(data, data + 2, out); + } + else + { + MEM_CPY_C(data, data_start, sizeof(uint16_t)); + size = text_encoding_decode_UTF16LE_single(data, data + 1, out); + } + } + + if (!size) + { + return 0; + } + else if (1 < size || max_ASCII_char < *out) + { + if (!buffer_push_back(output, unknown_ASCII_char)) + { + return 0; + } + } + else + { + if (!buffer_push_back(output, (uint8_t)(*out))) + { + return 0; + } + } + + data_start += size * sizeof(uint16_t); + } + + return 1; +} + +uint8_t text_encoding_UTF32_to_ASCII(const uint8_t* data_start, const uint8_t* data_finish, uint32_t* out, + uint8_t big_endian, void* output) +{ + while (data_start < data_finish) + { + static uint32_t data; + ptrdiff_t size = data_finish - data_start; + *out = unknown_ASCII_char; + + if ((size_t)size < sizeof(uint32_t)) + { + return 0; + } + + MEM_CPY_C(&data, data_start, sizeof(uint32_t)); + + if (big_endian) + { + size = text_encoding_change_UTF32_endian(&data, &data + 1, out); + } + else + { + size = text_encoding_decode_UTF32LE_single(&data, &data + 1, out); + } + + if (!size) + { + return 0; + } + else if (1 < size || max_ASCII_char < *out) + { + if (!buffer_push_back(output, unknown_ASCII_char)) + { + return 0; + } + } + else + { + if (!buffer_push_back(output, (uint8_t)(*out))) + { + return 0; + } + } + + data_start += size * sizeof(uint32_t); + } + + return 1; +} + uint8_t text_encoding_UTF_to_ASCII( const uint8_t* data_start, const uint8_t* data_finish, uint8_t encoding, void* output) @@ -319,27 +439,23 @@ uint8_t text_encoding_UTF_to_ASCII( switch (encoding) { case UTF8: - UTF_TO_ASCII(data_start, data_finish, size, text_encoding_decode_UTF8_single, uint8_t, out, output); + UTF8_TO_ASCII(data_start, data_finish, size, text_encoding_decode_UTF8_single, uint8_t, out, output); break; case BigEndianUnicode: case UTF16BE: - UTF_TO_ASCII(data_start, data_finish, size, text_encoding_decode_UTF16BE_single, uint16_t, out, output); - break; + return text_encoding_UTF16_to_ASCII(data_start, data_finish, out, 1, output); case Unicode: case UTF16LE: - UTF_TO_ASCII(data_start, data_finish, size, text_encoding_decode_UTF16LE_single, uint16_t, out, output); - break; + return text_encoding_UTF16_to_ASCII(data_start, data_finish, out, 0, output); case UTF32BE: - UTF_TO_ASCII(data_start, data_finish, size, text_encoding_change_UTF32_endian, uint32_t, out, output); - break; + return text_encoding_UTF32_to_ASCII(data_start, data_finish, out, 1, output); case UTF32: case UTF32LE: - UTF_TO_ASCII(data_start, data_finish, size, text_encoding_decode_UTF32LE_single, uint32_t, out, output); - break; + return text_encoding_UTF32_to_ASCII(data_start, data_finish, out, 0, output); default: return 0; @@ -1403,10 +1519,11 @@ uint8_t text_encoding_UTF16BE_to_UTF8(const uint16_t* data_start, const uint16_t return 0; } - uint32_t* decoded_UTF16BE = (uint32_t*)buffer_data(output, buffer_size(output) - sizeof(uint32_t)); + void* ptr = buffer_data(output, buffer_size(output) - sizeof(uint32_t)); + uint16_t* data_finish_ = (uint16_t*)ptr; + uint32_t* decoded_UTF16BE = (uint32_t*)ptr; - if ((data_start <= (uint16_t*)decoded_UTF16BE && - (uint16_t*)decoded_UTF16BE < data_finish) || + if ((data_start <= data_finish_ && data_finish_ < data_finish) || !buffer_resize(output, size)) { return 0; @@ -1450,10 +1567,12 @@ uint8_t text_encoding_UTF16LE_to_UTF8(const uint16_t* data_start, const uint16_t return 0; } - uint32_t* decoded_UTF16LE = (uint32_t*)buffer_data(output, buffer_size(output) - sizeof(uint32_t)); + void* ptr = buffer_data(output, buffer_size(output) - sizeof(uint32_t)); + uint16_t* data_finish_ = (uint16_t*)ptr; + uint32_t* decoded_UTF16LE = (uint32_t*)ptr; - if ((data_start <= (uint16_t*)decoded_UTF16LE && - (uint16_t*)decoded_UTF16LE < data_finish) || + if ((data_start <= data_finish_ && + data_finish_ < data_finish) || !buffer_resize(output, size)) { return 0; @@ -1565,6 +1684,156 @@ uint8_t text_encoding_UTF32BE_to_UTF8(const uint32_t* data_start, const uint32_t return 1; } + +uint8_t text_encoding_UTF16_to_UTF8(const uint8_t* data_start, const uint8_t* data_finish, uint8_t big_endian, + void* output) +{ + while (data_start < data_finish) + { + static uint8_t out[3]; + static uint16_t data[2]; + static uint32_t decoded; + ptrdiff_t size = data_finish - data_start; + + if ((size_t)size < sizeof(uint16_t)) + { + return 0; + } + + if (big_endian) + { + if (2 * sizeof(uint16_t) <= (size_t)size) + { + MEM_CPY_C(data, data_start, 2 * sizeof(uint16_t)); + size = text_encoding_decode_UTF16BE_single(data, data + 2, &decoded); + } + else + { + MEM_CPY_C(data, data_start, sizeof(uint16_t)); + size = text_encoding_decode_UTF16BE_single(data, data + 1, &decoded); + } + } + else + { + if (2 * sizeof(uint16_t) <= (size_t)size) + { + MEM_CPY_C(data, data_start, 2 * sizeof(uint16_t)); + size = text_encoding_decode_UTF16LE_single(data, data + 2, &decoded); + } + else + { + MEM_CPY_C(data, data_start, sizeof(uint16_t)); + size = text_encoding_decode_UTF16LE_single(data, data + 1, &decoded); + } + } + + if (!size) + { + return 0; + } + + data_start += size * sizeof(uint16_t); + size = text_encoding_encode_UTF8_single(decoded, out); + + if (!buffer_append(output, out, size)) + { + return 0; + } + } + + return 1; +} + +uint8_t text_encoding_UTF32_to_UTF8(const uint8_t* data_start, const uint8_t* data_finish, uint8_t big_endian, + void* output) +{ + while (data_start < data_finish) + { + static uint8_t out[3]; + static uint32_t data; + static uint32_t decoded; + ptrdiff_t size = data_finish - data_start; + + if ((size_t)size < sizeof(uint32_t)) + { + return 0; + } + + MEM_CPY_C(&data, data_start, sizeof(uint32_t)); + + if (big_endian) + { + size = text_encoding_change_UTF32_endian(&data, &data + 1, &decoded); + } + else + { + size = text_encoding_decode_UTF32LE_single(&data, &data + 1, &decoded); + } + + if (!size) + { + return 0; + } + + data_start += size * sizeof(uint32_t); + size = text_encoding_encode_UTF8_single(decoded, out); + + if (!buffer_append(output, out, size)) + { + return 0; + } + } + + return 1; +} + + +uint8_t text_encoding_UTF_to_UTF8( + const uint8_t* data_start, const uint8_t* data_finish, uint8_t encoding, void* output) +{ + if (NULL == data_start || + NULL == data_finish || + NULL == output || + data_finish < data_start) + { + return 0; + } + + if (data_finish == data_start) + { + return 1; + } + + switch (encoding) + { + case UTF7: + break; /*TODO: */ + + case UTF8: + return buffer_append(output, data_start, data_finish - data_start); + + case BigEndianUnicode: + case UTF16BE: + return text_encoding_UTF16_to_UTF8(data_start, data_finish, 1, output); + + case Unicode: + case UTF16LE: + return text_encoding_UTF16_to_UTF8(data_start, data_finish, 0, output); + + case UTF32BE: + return text_encoding_UTF32_to_UTF8(data_start, data_finish, 1, output); + + case UTF32: + case UTF32LE: + return text_encoding_UTF32_to_UTF8(data_start, data_finish, 0, output); + + default: + break; + } + + return 0; +} + #endif #ifndef NO_COMMON_UNIT static const uint8_t* text_encoding_str[] = diff --git a/text_encoding.h b/text_encoding.h index 486ffad..50c95f7 100644 --- a/text_encoding.h +++ b/text_encoding.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2020, 2022 TheVice + * Copyright (c) 2019 - 2020, 2022, 2024 TheVice * */ @@ -37,16 +37,14 @@ uint8_t text_encoding_get_BOM( uint8_t text_encoding_get_one_of_data_by_BOM( const uint8_t* data, ptrdiff_t data_length); -#ifndef NO_BUFFER_UNIT +#if !defined(NO_BUFFER_UNIT) && !defined(NO_COMMON_UNIT) uint8_t text_encoding_UTF_to_ASCII( const uint8_t* data_start, const uint8_t* data_finish, uint8_t encoding, void* output); uint8_t text_encoding_UTF_from_ASCII( const uint8_t* data_start, const uint8_t* data_finish, uint8_t encoding, void* output); -#ifndef NO_COMMON_UNIT uint8_t text_encoding_UTF16LE_from_code_page( const uint8_t* data_start, const uint8_t* data_finish, uint16_t code_page, void* output); #endif -#endif uint8_t text_encoding_encode_UTF8_single(uint32_t input, uint8_t* output); uint8_t text_encoding_decode_UTF8_single( @@ -83,6 +81,9 @@ uint8_t text_encoding_UTF8_to_UTF32BE( uint8_t text_encoding_UTF32BE_to_UTF8( const uint32_t* data_start, const uint32_t* data_finish, void* output); + +uint8_t text_encoding_UTF_to_UTF8( + const uint8_t* data_start, const uint8_t* data_finish, uint8_t encoding, void* output); #endif #ifndef NO_COMMON_UNIT diff --git a/version.c b/version.c index fbc739b..3502262 100644 --- a/version.c +++ b/version.c @@ -1,10 +1,12 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ +#include "stdc_secure_api.h" + #include "version.h" #include "buffer.h" @@ -13,6 +15,8 @@ #include "range.h" #include "string_unit.h" +#include + struct version_ { uint32_t major; @@ -118,8 +122,17 @@ uint8_t version_parse( break; } - uint32_t char_set; - *((uint32_t*)version) = (uint32_t)int64_parse(input_start, input_finish); + uint32_t char_set = (uint32_t)int64_parse(input_start, input_finish); +#if defined(__STDC_LIB_EXT1__) + + if (0 != memcpy_s(version, sizeof(uint32_t), &char_set, sizeof(uint32_t))) + { + return 0; + } + +#else + memcpy(version, &char_set, sizeof(uint32_t)); +#endif const uint8_t* start = input_start; input_start = string_find_any_symbol_like_or_not_like_that( input_start, input_finish, diff --git a/xml.c b/xml.c index 70d265b..3b84093 100644 --- a/xml.c +++ b/xml.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 - 2022 TheVice + * Copyright (c) 2019 - 2022, 2024 TheVice * */ @@ -337,7 +337,7 @@ uint8_t xml_read_ampersand_based_data( if (pos < start && buffer_size(digits)) { const uint16_t* digits_start = buffer_uint16_t_data(digits, 0); - const uint16_t* digits_finish = (const uint16_t*)(buffer_uint8_t_data(digits, 0) + buffer_size(digits)); + const uint16_t* digits_finish = (const uint16_t*)buffer_data_finish(digits); if (!text_encoding_UTF16LE_to_UTF8(digits_start, digits_finish, output) || !buffer_resize(digits, 0)) @@ -431,7 +431,7 @@ uint8_t xml_read_ampersand_based_data( if (buffer_size(digits)) { const uint16_t* digits_start = buffer_uint16_t_data(digits, 0); - const uint16_t* digits_finish = (const uint16_t*)(buffer_uint8_t_data(digits, 0) + buffer_size(digits)); + const uint16_t* digits_finish = (const uint16_t*)buffer_data_finish(digits); if (!text_encoding_UTF16LE_to_UTF8(digits_start, digits_finish, output) || !buffer_resize(digits, 0))