mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-13 05:06:30 +04:00
Api Symbols: replace asserts with checks (#3507)
* Api Symbols: replace asserts with checks * Api Symbols: replace asserts with checks part 2 * Update no args function signatures with void, to help compiler to track incorrect usage * More unavoidable void * Update PVS config and code to make it happy * Format sources * nfc: fix checks * dead code cleanup & include fixes Co-authored-by: gornekich <n.gorbadey@gmail.com> Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
@@ -7,22 +7,22 @@
|
||||
#define STREAM_BUFFER_SIZE (32U)
|
||||
|
||||
void stream_free(Stream* stream) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
stream->vtable->free(stream);
|
||||
}
|
||||
|
||||
void stream_clean(Stream* stream) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
stream->vtable->clean(stream);
|
||||
}
|
||||
|
||||
bool stream_eof(Stream* stream) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream->vtable->eof(stream);
|
||||
}
|
||||
|
||||
bool stream_seek(Stream* stream, int32_t offset, StreamOffset offset_type) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream->vtable->seek(stream, offset, offset_type);
|
||||
}
|
||||
|
||||
@@ -85,6 +85,8 @@ static bool stream_seek_to_char_backward(Stream* stream, char c) {
|
||||
}
|
||||
|
||||
bool stream_seek_to_char(Stream* stream, char c, StreamDirection direction) {
|
||||
furi_check(stream);
|
||||
|
||||
const size_t old_position = stream_tell(stream);
|
||||
|
||||
bool result = false;
|
||||
@@ -103,22 +105,22 @@ bool stream_seek_to_char(Stream* stream, char c, StreamDirection direction) {
|
||||
}
|
||||
|
||||
size_t stream_tell(Stream* stream) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream->vtable->tell(stream);
|
||||
}
|
||||
|
||||
size_t stream_size(Stream* stream) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream->vtable->size(stream);
|
||||
}
|
||||
|
||||
size_t stream_write(Stream* stream, const uint8_t* data, size_t size) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream->vtable->write(stream, data, size);
|
||||
}
|
||||
|
||||
size_t stream_read(Stream* stream, uint8_t* data, size_t size) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream->vtable->read(stream, data, size);
|
||||
}
|
||||
|
||||
@@ -127,7 +129,7 @@ bool stream_delete_and_insert(
|
||||
size_t delete_size,
|
||||
StreamWriteCB write_callback,
|
||||
const void* ctx) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream->vtable->delete_and_insert(stream, delete_size, write_callback, ctx);
|
||||
}
|
||||
|
||||
@@ -139,13 +141,16 @@ typedef struct {
|
||||
} StreamWriteData;
|
||||
|
||||
static bool stream_write_struct(Stream* stream, const void* context) {
|
||||
furi_assert(stream);
|
||||
furi_assert(context);
|
||||
furi_check(stream);
|
||||
furi_check(context);
|
||||
const StreamWriteData* write_data = context;
|
||||
return (stream_write(stream, write_data->data, write_data->size) == write_data->size);
|
||||
}
|
||||
|
||||
bool stream_read_line(Stream* stream, FuriString* str_result) {
|
||||
furi_check(stream);
|
||||
furi_check(str_result);
|
||||
|
||||
furi_string_reset(str_result);
|
||||
uint8_t buffer[STREAM_BUFFER_SIZE];
|
||||
|
||||
@@ -180,28 +185,28 @@ bool stream_read_line(Stream* stream, FuriString* str_result) {
|
||||
}
|
||||
|
||||
bool stream_rewind(Stream* stream) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream_seek(stream, 0, StreamOffsetFromStart);
|
||||
}
|
||||
|
||||
size_t stream_write_char(Stream* stream, char c) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream_write(stream, (const uint8_t*)&c, 1);
|
||||
}
|
||||
|
||||
size_t stream_write_string(Stream* stream, FuriString* string) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream_write(
|
||||
stream, (const uint8_t*)furi_string_get_cstr(string), furi_string_size(string));
|
||||
}
|
||||
|
||||
size_t stream_write_cstring(Stream* stream, const char* string) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream_write(stream, (const uint8_t*)string, strlen(string));
|
||||
}
|
||||
|
||||
size_t stream_write_format(Stream* stream, const char* format, ...) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
size_t size;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
@@ -211,7 +216,7 @@ size_t stream_write_format(Stream* stream, const char* format, ...) {
|
||||
}
|
||||
|
||||
size_t stream_write_vaformat(Stream* stream, const char* format, va_list args) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
FuriString* data;
|
||||
data = furi_string_alloc_vprintf(format, args);
|
||||
size_t size = stream_write_string(stream, data);
|
||||
@@ -221,28 +226,28 @@ size_t stream_write_vaformat(Stream* stream, const char* format, va_list args) {
|
||||
}
|
||||
|
||||
bool stream_insert(Stream* stream, const uint8_t* data, size_t size) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
StreamWriteData write_data = {.data = data, .size = size};
|
||||
return stream_delete_and_insert(stream, 0, stream_write_struct, &write_data);
|
||||
}
|
||||
|
||||
bool stream_insert_char(Stream* stream, char c) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream_delete_and_insert_char(stream, 0, c);
|
||||
}
|
||||
|
||||
bool stream_insert_string(Stream* stream, FuriString* string) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream_delete_and_insert_string(stream, 0, string);
|
||||
}
|
||||
|
||||
bool stream_insert_cstring(Stream* stream, const char* string) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream_delete_and_insert_cstring(stream, 0, string);
|
||||
}
|
||||
|
||||
bool stream_insert_format(Stream* stream, const char* format, ...) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
bool result = stream_insert_vaformat(stream, format, args);
|
||||
@@ -252,31 +257,31 @@ bool stream_insert_format(Stream* stream, const char* format, ...) {
|
||||
}
|
||||
|
||||
bool stream_insert_vaformat(Stream* stream, const char* format, va_list args) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream_delete_and_insert_vaformat(stream, 0, format, args);
|
||||
}
|
||||
|
||||
bool stream_delete_and_insert_char(Stream* stream, size_t delete_size, char c) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
StreamWriteData write_data = {.data = (uint8_t*)&c, .size = 1};
|
||||
return stream_delete_and_insert(stream, delete_size, stream_write_struct, &write_data);
|
||||
}
|
||||
|
||||
bool stream_delete_and_insert_string(Stream* stream, size_t delete_size, FuriString* string) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
StreamWriteData write_data = {
|
||||
.data = (uint8_t*)furi_string_get_cstr(string), .size = furi_string_size(string)};
|
||||
return stream_delete_and_insert(stream, delete_size, stream_write_struct, &write_data);
|
||||
}
|
||||
|
||||
bool stream_delete_and_insert_cstring(Stream* stream, size_t delete_size, const char* string) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
StreamWriteData write_data = {.data = (uint8_t*)string, .size = strlen(string)};
|
||||
return stream_delete_and_insert(stream, delete_size, stream_write_struct, &write_data);
|
||||
}
|
||||
|
||||
bool stream_delete_and_insert_format(Stream* stream, size_t delete_size, const char* format, ...) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
bool result = stream_delete_and_insert_vaformat(stream, delete_size, format, args);
|
||||
@@ -290,9 +295,9 @@ bool stream_delete_and_insert_vaformat(
|
||||
size_t delete_size,
|
||||
const char* format,
|
||||
va_list args) {
|
||||
furi_assert(stream);
|
||||
FuriString* data;
|
||||
data = furi_string_alloc_vprintf(format, args);
|
||||
furi_check(stream);
|
||||
|
||||
FuriString* data = furi_string_alloc_vprintf(format, args);
|
||||
StreamWriteData write_data = {
|
||||
.data = (uint8_t*)furi_string_get_cstr(data), .size = furi_string_size(data)};
|
||||
bool result = stream_delete_and_insert(stream, delete_size, stream_write_struct, &write_data);
|
||||
@@ -302,11 +307,14 @@ bool stream_delete_and_insert_vaformat(
|
||||
}
|
||||
|
||||
bool stream_delete(Stream* stream, size_t size) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
return stream_delete_and_insert(stream, size, NULL, NULL);
|
||||
}
|
||||
|
||||
size_t stream_copy(Stream* stream_from, Stream* stream_to, size_t size) {
|
||||
furi_check(stream_from);
|
||||
furi_check(stream_to);
|
||||
|
||||
uint8_t* buffer = malloc(STREAM_CACHE_SIZE);
|
||||
size_t copied = 0;
|
||||
|
||||
@@ -330,6 +338,9 @@ size_t stream_copy(Stream* stream_from, Stream* stream_to, size_t size) {
|
||||
}
|
||||
|
||||
size_t stream_copy_full(Stream* stream_from, Stream* stream_to) {
|
||||
furi_check(stream_from);
|
||||
furi_check(stream_to);
|
||||
|
||||
size_t was_written = 0;
|
||||
|
||||
do {
|
||||
@@ -342,6 +353,8 @@ size_t stream_copy_full(Stream* stream_from, Stream* stream_to) {
|
||||
}
|
||||
|
||||
bool stream_split(Stream* stream, Stream* stream_left, Stream* stream_right) {
|
||||
furi_check(stream);
|
||||
|
||||
bool result = false;
|
||||
size_t size = stream_size(stream);
|
||||
size_t tell = stream_tell(stream);
|
||||
@@ -363,6 +376,9 @@ bool stream_split(Stream* stream, Stream* stream_left, Stream* stream_right) {
|
||||
}
|
||||
|
||||
size_t stream_load_from_file(Stream* stream, Storage* storage, const char* path) {
|
||||
furi_check(stream);
|
||||
furi_check(storage);
|
||||
|
||||
size_t was_written = 0;
|
||||
Stream* file = file_stream_alloc(storage);
|
||||
|
||||
@@ -376,6 +392,9 @@ size_t stream_load_from_file(Stream* stream, Storage* storage, const char* path)
|
||||
}
|
||||
|
||||
size_t stream_save_to_file(Stream* stream, Storage* storage, const char* path, FS_OpenMode mode) {
|
||||
furi_check(stream);
|
||||
furi_check(storage);
|
||||
|
||||
size_t was_written = 0;
|
||||
Stream* file = file_stream_alloc(storage);
|
||||
|
||||
@@ -389,6 +408,8 @@ size_t stream_save_to_file(Stream* stream, Storage* storage, const char* path, F
|
||||
}
|
||||
|
||||
void stream_dump_data(Stream* stream) {
|
||||
furi_check(stream);
|
||||
|
||||
size_t size = stream_size(stream);
|
||||
size_t tell = stream_tell(stream);
|
||||
printf("stream %p\r\n", stream);
|
||||
|
||||
Reference in New Issue
Block a user