mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-24 01:28:11 -07: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:
@@ -58,14 +58,14 @@ bool buffered_file_stream_open(
|
||||
const char* path,
|
||||
FS_AccessMode access_mode,
|
||||
FS_OpenMode open_mode) {
|
||||
furi_assert(_stream);
|
||||
furi_check(_stream);
|
||||
BufferedFileStream* stream = (BufferedFileStream*)_stream;
|
||||
furi_check(stream->stream_base.vtable == &buffered_file_stream_vtable);
|
||||
return file_stream_open(stream->file_stream, path, access_mode, open_mode);
|
||||
}
|
||||
|
||||
bool buffered_file_stream_close(Stream* _stream) {
|
||||
furi_assert(_stream);
|
||||
furi_check(_stream);
|
||||
BufferedFileStream* stream = (BufferedFileStream*)_stream;
|
||||
furi_check(stream->stream_base.vtable == &buffered_file_stream_vtable);
|
||||
bool success = false;
|
||||
@@ -80,21 +80,21 @@ bool buffered_file_stream_close(Stream* _stream) {
|
||||
}
|
||||
|
||||
bool buffered_file_stream_sync(Stream* _stream) {
|
||||
furi_assert(_stream);
|
||||
furi_check(_stream);
|
||||
BufferedFileStream* stream = (BufferedFileStream*)_stream;
|
||||
furi_check(stream->stream_base.vtable == &buffered_file_stream_vtable);
|
||||
return stream->sync_pending ? buffered_file_stream_flush(stream) : true;
|
||||
}
|
||||
|
||||
FS_Error buffered_file_stream_get_error(Stream* _stream) {
|
||||
furi_assert(_stream);
|
||||
furi_check(_stream);
|
||||
BufferedFileStream* stream = (BufferedFileStream*)_stream;
|
||||
furi_check(stream->stream_base.vtable == &buffered_file_stream_vtable);
|
||||
return file_stream_get_error(stream->file_stream);
|
||||
}
|
||||
|
||||
static void buffered_file_stream_free(BufferedFileStream* stream) {
|
||||
furi_assert(stream);
|
||||
furi_check(stream);
|
||||
buffered_file_stream_sync((Stream*)stream);
|
||||
stream_free(stream->file_stream);
|
||||
stream_cache_free(stream->cache);
|
||||
|
||||
@@ -35,6 +35,8 @@ const StreamVTable file_stream_vtable = {
|
||||
};
|
||||
|
||||
Stream* file_stream_alloc(Storage* storage) {
|
||||
furi_check(storage);
|
||||
|
||||
FileStream* stream = malloc(sizeof(FileStream));
|
||||
stream->file = storage_file_alloc(storage);
|
||||
stream->storage = storage;
|
||||
@@ -48,21 +50,21 @@ bool file_stream_open(
|
||||
const char* path,
|
||||
FS_AccessMode access_mode,
|
||||
FS_OpenMode open_mode) {
|
||||
furi_assert(_stream);
|
||||
furi_check(_stream);
|
||||
FileStream* stream = (FileStream*)_stream;
|
||||
furi_check(stream->stream_base.vtable == &file_stream_vtable);
|
||||
return storage_file_open(stream->file, path, access_mode, open_mode);
|
||||
}
|
||||
|
||||
bool file_stream_close(Stream* _stream) {
|
||||
furi_assert(_stream);
|
||||
furi_check(_stream);
|
||||
FileStream* stream = (FileStream*)_stream;
|
||||
furi_check(stream->stream_base.vtable == &file_stream_vtable);
|
||||
return storage_file_close(stream->file);
|
||||
}
|
||||
|
||||
FS_Error file_stream_get_error(Stream* _stream) {
|
||||
furi_assert(_stream);
|
||||
furi_check(_stream);
|
||||
FileStream* stream = (FileStream*)_stream;
|
||||
furi_check(stream->stream_base.vtable == &file_stream_vtable);
|
||||
return storage_file_get_error(stream->file);
|
||||
|
||||
+52
-31
@@ -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);
|
||||
|
||||
@@ -8,7 +8,7 @@ struct StreamCache {
|
||||
size_t position;
|
||||
};
|
||||
|
||||
StreamCache* stream_cache_alloc() {
|
||||
StreamCache* stream_cache_alloc(void) {
|
||||
StreamCache* cache = malloc(sizeof(StreamCache));
|
||||
cache->data_size = 0;
|
||||
cache->position = 0;
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef struct StreamCache StreamCache;
|
||||
* Allocate stream cache.
|
||||
* @return StreamCache* pointer to a StreamCache instance
|
||||
*/
|
||||
StreamCache* stream_cache_alloc();
|
||||
StreamCache* stream_cache_alloc(void);
|
||||
|
||||
/**
|
||||
* Free stream cache.
|
||||
|
||||
@@ -37,7 +37,7 @@ const StreamVTable string_stream_vtable = {
|
||||
.delete_and_insert = (StreamDeleteAndInsertFn)string_stream_delete_and_insert,
|
||||
};
|
||||
|
||||
Stream* string_stream_alloc() {
|
||||
Stream* string_stream_alloc(void) {
|
||||
StringStream* stream = malloc(sizeof(StringStream));
|
||||
stream->string = furi_string_alloc();
|
||||
stream->index = 0;
|
||||
|
||||
@@ -10,7 +10,7 @@ extern "C" {
|
||||
* Allocate string stream
|
||||
* @return Stream*
|
||||
*/
|
||||
Stream* string_stream_alloc();
|
||||
Stream* string_stream_alloc(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user