Skip to content

Commit

Permalink
[buffer] function buffer_data_finish return NULL for empty buffer.
Browse files Browse the repository at this point in the history
This behavior is required to match with same if begin of buffer required
to get in same condition.

[echo|exec|file_system] made casting meet with requirements from some
environments in order to meet align policy.
  • Loading branch information
TheVice committed Apr 15, 2024
1 parent 9a9bfd5 commit 0698eca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
3 changes: 2 additions & 1 deletion buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ 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)
NULL == the_buffer->data ||
the_buffer->size <= 0)
{
return NULL;
}
Expand Down
16 changes: 12 additions & 4 deletions echo.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 - 2022 TheVice
* Copyright (c) 2019 - 2022, 2024 TheVice
*
*/

Expand Down Expand Up @@ -181,9 +181,17 @@ uint8_t echo(
else
{
#if defined(_WIN32)
result = (is_output_standard && REQUIRED_UNICODE_CONSOLE_AT_WINDOWS(encoding)) ?
echo_win32(echo_get_win32_console_output(level), (const uint16_t*)message, (uint16_t)message_length) :
(message_length == (ptrdiff_t)file_write(message, sizeof(uint8_t), message_length, file_stream));

if (is_output_standard && REQUIRED_UNICODE_CONSOLE_AT_WINDOWS(encoding))
{
result = echo_win32(echo_get_win32_console_output(level), (const uint16_t*)buffer_data(new_message, 0),
(uint16_t)message_length);
}
else
{
result = (message_length == (ptrdiff_t)file_write(message, sizeof(uint8_t), message_length, file_stream));
}

#else
result = (message_length == (ptrdiff_t)file_write(message, sizeof(uint8_t), message_length, file_stream));
#endif
Expand Down
2 changes: 1 addition & 1 deletion exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ uint8_t exec(
}

const wchar_t* start = programW;
const wchar_t* finish = (const wchar_t*)(buffer_uint8_t_data(application, 0) + buffer_size(application));
const wchar_t* finish = (const wchar_t*)buffer_data_finish(application);
/**/
ptrdiff_t indices[3];
memset(indices, 0, sizeof(indices));
Expand Down
10 changes: 5 additions & 5 deletions file_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ uint8_t directory_enumerate_file_system_entries_wchar_t(

if (file_system_get_id_of_file_entry() == entry_type)
{
finish = (const wchar_t*)(buffer_uint8_t_data(pattern, 0) + sizeof(wchar_t) * new_index);
finish = buffer_wchar_t_data(pattern, 0) + (sizeof(wchar_t) * new_index) / sizeof(wchar_t);

if (!buffer_resize(pattern, index * sizeof(wchar_t)) ||
!buffer_append_wchar_t(pattern, finish, delta))
Expand All @@ -334,7 +334,7 @@ uint8_t directory_enumerate_file_system_entries_wchar_t(
}
else if (file_system_get_id_of_directory_entry() == entry_type)
{
finish = (const wchar_t*)(buffer_uint8_t_data(pattern, 0) + sizeof(wchar_t) * new_index);
finish = buffer_wchar_t_data(pattern, 0) + (sizeof(wchar_t) * new_index) / sizeof(wchar_t);

if (!buffer_resize(pattern, index * sizeof(wchar_t)) ||
!buffer_append_wchar_t(pattern, finish, delta))
Expand All @@ -346,7 +346,7 @@ uint8_t directory_enumerate_file_system_entries_wchar_t(
continue;
}

finish = (const wchar_t*)(buffer_uint8_t_data(pattern, 0) + sizeof(wchar_t) * new_index);
finish = buffer_wchar_t_data(pattern, 0) + (sizeof(wchar_t) * new_index) / sizeof(wchar_t);

if (UTF8 == output_encoding)
{
Expand Down Expand Up @@ -597,7 +597,7 @@ uint8_t directory_create(const uint8_t* path)
wchar_t* path_start = buffer_wchar_t_data(pathW, 0);
/**/
const wchar_t* start = path_start;
const wchar_t* finish = (const wchar_t*)(buffer_uint8_t_data(pathW, 0) + buffer_size(pathW));
const wchar_t* finish = (const wchar_t*)buffer_data_finish(pathW);
/**/
file_system_set_position_after_pre_root_wchar_t(&start);

Expand Down Expand Up @@ -761,7 +761,7 @@ uint8_t directory_delete(const uint8_t* path)

#if defined(_WIN32)
const wchar_t* start = buffer_wchar_t_data(entries, 0);
const wchar_t* finish = (const wchar_t*)(buffer_uint8_t_data(entries, 0) + buffer_size(entries));
const wchar_t* finish = (const wchar_t*)buffer_data_finish(entries);
#else
const uint8_t* start = buffer_uint8_t_data(entries, 0);
const uint8_t* finish = start + buffer_size(entries);
Expand Down

0 comments on commit 0698eca

Please sign in to comment.