[FL-2811] Fix PVS-Studio warnings (#2142)

Co-authored-by: あく <alleteam@gmail.com>
Co-authored-by: gornekich <n.gorbadey@gmail.com>
This commit is contained in:
Georgii Surkov
2022-12-26 15:13:30 +03:00
committed by GitHub
parent ad3bff0b67
commit 8582670a34
201 changed files with 719 additions and 743 deletions

View File

@@ -117,7 +117,7 @@ FURI_NORETURN void __furi_crash() {
if(debug) {
furi_hal_console_puts("\r\nSystem halted. Connect debugger for more info\r\n");
furi_hal_console_puts("\033[0m\r\n");
RESTORE_REGISTERS_AND_HALT_MCU(debug);
RESTORE_REGISTERS_AND_HALT_MCU(true);
} else {
furi_hal_rtc_set_fault_data((uint32_t)__furi_check_message);
furi_hal_console_puts("\r\nRebooting system.\r\n");

View File

@@ -93,7 +93,7 @@ extern "C" {
#endif
#ifndef FURI_BIT_CLEAR
#define FURI_BIT_CLEAR(x, n) ((x) &= ~(1 << (n)))
#define FURI_BIT_CLEAR(x, n) ((x) &= ~(1UL << (n)))
#endif
#define FURI_SW_MEMBARRIER() asm volatile("" : : : "memory")

View File

@@ -9,7 +9,11 @@
FuriEventFlag* furi_event_flag_alloc() {
furi_assert(!FURI_IS_IRQ_MODE());
return ((FuriEventFlag*)xEventGroupCreate());
EventGroupHandle_t handle = xEventGroupCreate();
furi_check(handle);
return ((FuriEventFlag*)handle);
}
void furi_event_flag_free(FuriEventFlag* instance) {

View File

@@ -212,7 +212,8 @@ static inline void traceFREE(void* pointer, size_t size) {
MemmgrHeapThreadDict_get(memmgr_heap_thread_dict, (uint32_t)thread_id);
if(alloc_dict) {
// In some cases thread may want to release memory that was not allocated by it
(void)MemmgrHeapAllocDict_erase(*alloc_dict, (uint32_t)pointer);
const bool res = MemmgrHeapAllocDict_erase(*alloc_dict, (uint32_t)pointer);
UNUSED(res);
}
memmgr_heap_thread_trace_depth--;
}
@@ -520,8 +521,8 @@ void vPortFree(void* pv) {
{
furi_assert((size_t)pv >= SRAM_BASE);
furi_assert((size_t)pv < SRAM_BASE + 1024 * 256);
furi_assert(pxLink->xBlockSize >= xHeapStructSize);
furi_assert((pxLink->xBlockSize - xHeapStructSize) < 1024 * 256);
furi_assert((int32_t)(pxLink->xBlockSize - xHeapStructSize) >= 0);
/* Add this block to the list of free blocks. */
xFreeBytesRemaining += pxLink->xBlockSize;

View File

@@ -7,7 +7,10 @@
FuriMessageQueue* furi_message_queue_alloc(uint32_t msg_count, uint32_t msg_size) {
furi_assert((furi_is_irq_context() == 0U) && (msg_count > 0U) && (msg_size > 0U));
return ((FuriMessageQueue*)xQueueCreate(msg_count, msg_size));
QueueHandle_t handle = xQueueCreate(msg_count, msg_size);
furi_check(handle);
return ((FuriMessageQueue*)handle);
}
void furi_message_queue_free(FuriMessageQueue* instance) {

View File

@@ -30,6 +30,8 @@ FuriMutex* furi_mutex_alloc(FuriMutexType type) {
void furi_mutex_free(FuriMutex* instance) {
furi_assert(!FURI_IS_IRQ_MODE());
furi_assert(instance);
vSemaphoreDelete((SemaphoreHandle_t)((uint32_t)instance & ~1U));
}

View File

@@ -1,18 +1,26 @@
#include "base.h"
#include "check.h"
#include "stream_buffer.h"
#include "common_defines.h"
#include <FreeRTOS.h>
#include <FreeRTOS-Kernel/include/stream_buffer.h>
FuriStreamBuffer* furi_stream_buffer_alloc(size_t size, size_t trigger_level) {
return xStreamBufferCreate(size, trigger_level);
furi_assert(size != 0);
StreamBufferHandle_t handle = xStreamBufferCreate(size, trigger_level);
furi_check(handle);
return handle;
};
void furi_stream_buffer_free(FuriStreamBuffer* stream_buffer) {
furi_assert(stream_buffer);
vStreamBufferDelete(stream_buffer);
};
bool furi_stream_set_trigger_level(FuriStreamBuffer* stream_buffer, size_t trigger_level) {
furi_assert(stream_buffer);
return xStreamBufferSetTriggerLevel(stream_buffer, trigger_level) == pdTRUE;
};

View File

@@ -29,16 +29,16 @@ FuriString* furi_string_alloc() {
}
FuriString* furi_string_alloc_set(const FuriString* s) {
FuriString* string = malloc(sizeof(FuriString)); //-V773
FuriString* string = malloc(sizeof(FuriString)); //-V799
string_init_set(string->string, s->string);
return string;
}
} //-V773
FuriString* furi_string_alloc_set_str(const char cstr[]) {
FuriString* string = malloc(sizeof(FuriString)); //-V773
FuriString* string = malloc(sizeof(FuriString)); //-V799
string_init_set(string->string, cstr);
return string;
}
} //-V773
FuriString* furi_string_alloc_printf(const char format[], ...) {
va_list args;
@@ -299,4 +299,4 @@ void furi_string_utf8_decode(char c, FuriStringUTF8State* state, FuriStringUnico
m_str1ng_utf8_state_e m_state = furi_state_to_state(*state);
m_str1ng_utf8_decode(c, &m_state, unicode);
*state = state_to_furi_state(m_state);
}
}

View File

@@ -49,9 +49,9 @@ static size_t __furi_thread_stdout_write(FuriThread* thread, const char* data, s
static int32_t __furi_thread_stdout_flush(FuriThread* thread);
/** Catch threads that are trying to exit wrong way */
__attribute__((__noreturn__)) void furi_thread_catch() {
__attribute__((__noreturn__)) void furi_thread_catch() { //-V1082
asm volatile("nop"); // extra magic
furi_crash("You are doing it wrong");
furi_crash("You are doing it wrong"); //-V779
__builtin_unreachable();
}
@@ -84,10 +84,10 @@ static void furi_thread_body(void* context) {
if(thread->heap_trace_enabled == true) {
furi_delay_ms(33);
thread->heap_size = memmgr_heap_get_thread_memory((FuriThreadId)task_handle);
furi_log_print_format(
furi_log_print_format( //-V576
thread->heap_size ? FuriLogLevelError : FuriLogLevelInfo,
TAG,
"%s allocation balance: %d",
"%s allocation balance: %u",
thread->name ? thread->name : "Thread",
thread->heap_size);
memmgr_heap_disable_thread_trace((FuriThreadId)task_handle);

View File

@@ -32,44 +32,28 @@ FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* co
TimerHandle_t hTimer;
TimerCallback_t* callb;
UBaseType_t reload;
uint32_t callb_dyn;
hTimer = NULL;
callb = NULL;
callb_dyn = 0U;
/* Dynamic memory allocation is available: if memory for callback and */
/* its context is not provided, allocate it from dynamic memory pool */
if(callb == NULL) {
callb = (TimerCallback_t*)malloc(sizeof(TimerCallback_t));
callb = (TimerCallback_t*)malloc(sizeof(TimerCallback_t));
if(callb != NULL) {
/* Callback memory was allocated from dynamic pool, set flag */
callb_dyn = 1U;
}
callb->func = func;
callb->context = context;
if(type == FuriTimerTypeOnce) {
reload = pdFALSE;
} else {
reload = pdTRUE;
}
if(callb != NULL) {
callb->func = func;
callb->context = context;
if(type == FuriTimerTypeOnce) {
reload = pdFALSE;
} else {
reload = pdTRUE;
}
/* Store callback memory dynamic allocation flag */
callb = (TimerCallback_t*)((uint32_t)callb | callb_dyn);
// TimerCallback function is always provided as a callback and is used to call application
// specified function with its context both stored in structure callb.
hTimer = xTimerCreate(NULL, 1, reload, callb, TimerCallback);
if((hTimer == NULL) && (callb != NULL) && (callb_dyn == 1U)) {
/* Failed to create a timer, release allocated resources */
callb = (TimerCallback_t*)((uint32_t)callb & ~1U);
free(callb);
}
}
/* Store callback memory dynamic allocation flag */
callb = (TimerCallback_t*)((uint32_t)callb | 1U);
// TimerCallback function is always provided as a callback and is used to call application
// specified function with its context both stored in structure callb.
hTimer = xTimerCreate(NULL, 1, reload, callb, TimerCallback);
furi_check(hTimer);
/* Return timer ID */
return ((FuriTimer*)hTimer);