[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

@@ -568,12 +568,12 @@ void dap_common_usb_set_state_callback(DapStateCallback callback) {
static void* dap_usb_alloc_string_descr(const char* str) {
furi_assert(str);
uint8_t len = strlen(str);
uint8_t wlen = (len + 1) * sizeof(uint16_t);
size_t len = strlen(str);
size_t wlen = (len + 1) * sizeof(uint16_t);
struct usb_string_descriptor* dev_str_desc = malloc(wlen);
dev_str_desc->bLength = wlen;
dev_str_desc->bDescriptorType = USB_DTYPE_STRING;
for(uint8_t i = 0; i < len; i++) {
for(size_t i = 0; i < len; i++) {
dev_str_desc->wString[i] = str[i];
}
@@ -974,4 +974,4 @@ static usbd_respond hid_control(usbd_device* dev, usbd_ctlreq* req, usbd_rqc_cal
}
return usbd_fail;
}
}

View File

@@ -249,30 +249,19 @@ static void hid_keyboard_draw_callback(Canvas* canvas, void* context) {
static uint8_t hid_keyboard_get_selected_key(HidKeyboardModel* model) {
HidKeyboardKey key = hid_keyboard_keyset[model->y][model->x];
// Use upper case if shift is toggled
bool useUppercase = model->shift;
// Check if the key has an upper case version
bool hasUppercase = key.shift_key != 0;
if(useUppercase && hasUppercase)
return key.value;
else
return key.value;
return key.value;
}
static void hid_keyboard_get_select_key(HidKeyboardModel* model, HidKeyboardPoint delta) {
// Keep going until a valid spot is found, this allows for nulls and zero width keys in the map
do {
if(((int8_t)model->y) + delta.y < 0)
model->y = ROW_COUNT - 1;
else
model->y = (model->y + delta.y) % ROW_COUNT;
const int delta_sum = model->y + delta.y;
model->y = delta_sum < 0 ? ROW_COUNT - 1 : delta_sum % ROW_COUNT;
} while(delta.y != 0 && hid_keyboard_keyset[model->y][model->x].value == 0);
do {
if(((int8_t)model->x) + delta.x < 0)
model->x = COLUMN_COUNT - 1;
else
model->x = (model->x + delta.x) % COLUMN_COUNT;
const int delta_sum = model->x + delta.x;
model->x = delta_sum < 0 ? COLUMN_COUNT - 1 : delta_sum % COLUMN_COUNT;
} while(delta.x != 0 && hid_keyboard_keyset[model->y][model->x].width ==
0); // Skip zero width keys, pretend they are one key
}

View File

@@ -180,7 +180,7 @@ static void render_callback(Canvas* canvas, void* ctx) {
// note stack view_port
x_pos = 73;
y_pos = 0;
y_pos = 0; //-V1048
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
canvas_draw_frame(canvas, x_pos, y_pos, 49, 64);

View File

@@ -111,9 +111,9 @@ static void init_opt_select_LUT(void) {
***********************************************************************************/
#define loclass_opt__select(x, y, r) \
(4 & (((r & (r << 2)) >> 5) ^ ((r & ~(r << 2)) >> 4) ^ ((r | r << 2) >> 3))) | \
(2 & (((r | r << 2) >> 6) ^ ((r | r << 2) >> 1) ^ (r >> 5) ^ r ^ ((x ^ y) << 1))) | \
(1 & (((r & ~(r << 2)) >> 4) ^ ((r & (r << 2)) >> 3) ^ r ^ x))
(4 & ((((r) & ((r) << 2)) >> 5) ^ (((r) & ~((r) << 2)) >> 4) ^ (((r) | (r) << 2) >> 3))) | \
(2 & ((((r) | (r) << 2) >> 6) ^ (((r) | (r) << 2) >> 1) ^ ((r) >> 5) ^ (r) ^ (((x) ^ (y)) << 1))) | \
(1 & ((((r) & ~((r) << 2)) >> 4) ^ (((r) & ((r) << 2)) >> 3) ^ (r) ^ (x)))
static void loclass_opt_successor(const uint8_t* k, LoclassState_t* s, uint8_t y) {
uint16_t Tt = s->t & 0xc533;
@@ -149,30 +149,11 @@ static void loclass_opt_suc(
uint8_t length,
bool add32Zeroes) {
for(int i = 0; i < length; i++) {
uint8_t head;
head = in[i];
loclass_opt_successor(k, s, head);
head >>= 1;
loclass_opt_successor(k, s, head);
head >>= 1;
loclass_opt_successor(k, s, head);
head >>= 1;
loclass_opt_successor(k, s, head);
head >>= 1;
loclass_opt_successor(k, s, head);
head >>= 1;
loclass_opt_successor(k, s, head);
head >>= 1;
loclass_opt_successor(k, s, head);
head >>= 1;
loclass_opt_successor(k, s, head);
uint8_t head = in[i];
for(int j = 0; j < 8; j++) {
loclass_opt_successor(k, s, head);
head >>= 1;
}
}
//For tag MAC, an additional 32 zeroes
if(add32Zeroes) {

View File

@@ -143,7 +143,7 @@ ReturnCode picopass_read_preauth(PicopassBlock* AA1) {
AA1[PICOPASS_CSN_BLOCK_INDEX].data[7]);
rfalPicoPassReadBlockRes cfg = {0};
err = rfalPicoPassPollerReadBlock(PICOPASS_CONFIG_BLOCK_INDEX, &cfg);
rfalPicoPassPollerReadBlock(PICOPASS_CONFIG_BLOCK_INDEX, &cfg);
memcpy(AA1[PICOPASS_CONFIG_BLOCK_INDEX].data, cfg.data, sizeof(cfg.data));
FURI_LOG_D(
TAG,
@@ -158,7 +158,7 @@ ReturnCode picopass_read_preauth(PicopassBlock* AA1) {
AA1[PICOPASS_CONFIG_BLOCK_INDEX].data[7]);
rfalPicoPassReadBlockRes aia;
err = rfalPicoPassPollerReadBlock(PICOPASS_AIA_BLOCK_INDEX, &aia);
rfalPicoPassPollerReadBlock(PICOPASS_AIA_BLOCK_INDEX, &aia);
memcpy(AA1[PICOPASS_AIA_BLOCK_INDEX].data, aia.data, sizeof(aia.data));
FURI_LOG_D(
TAG,
@@ -221,7 +221,7 @@ ReturnCode picopass_auth(PicopassBlock* AA1, PicopassPacs* pacs) {
while(iclass_elite_dict_get_next_key(dict, key)) {
FURI_LOG_D(
TAG,
"Try to auth with key %d %02x%02x%02x%02x%02x%02x%02x%02x",
"Try to auth with key %zu %02x%02x%02x%02x%02x%02x%02x%02x",
index++,
key[0],
key[1],
@@ -249,9 +249,7 @@ ReturnCode picopass_auth(PicopassBlock* AA1, PicopassPacs* pacs) {
}
}
if(dict) {
iclass_elite_dict_free(dict);
}
iclass_elite_dict_free(dict);
return err;
}

View File

@@ -54,7 +54,7 @@ bool picopass_scene_save_name_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == PicopassCustomEventTextInputDone) {
if(strcmp(picopass->dev->dev_name, "")) {
if(strcmp(picopass->dev->dev_name, "") != 0) {
// picopass_device_delete(picopass->dev, true);
}
strlcpy(

View File

@@ -15,12 +15,12 @@ static void
app->pwm_freq = freq;
app->pwm_duty = duty;
if(app->pwm_ch != pwm_ch_id[channel_id]) {
if(app->pwm_ch != pwm_ch_id[channel_id]) { //-V1051
app->pwm_ch_prev = app->pwm_ch;
app->pwm_ch = pwm_ch_id[channel_id];
view_dispatcher_send_custom_event(app->view_dispatcher, SignalGenPwmEventChannelChange);
} else {
app->pwm_ch = pwm_ch_id[channel_id];
app->pwm_ch = pwm_ch_id[channel_id]; //-V1048
view_dispatcher_send_custom_event(app->view_dispatcher, SignalGenPwmEventUpdate);
}
}

View File

@@ -127,12 +127,12 @@ static void signal_gen_pwm_draw_callback(Canvas* canvas, void* _model) {
char* line_label = NULL;
char val_text[16];
for(uint8_t line = 0; line < LineIndexTotalCount; line++) {
for(size_t line = 0; line < LineIndexTotalCount; line++) {
if(line == LineIndexChannel) {
line_label = "GPIO Pin";
} else if(line == LineIndexFrequency) {
line_label = "Frequency";
} else if(line == LineIndexDuty) {
} else if(line == LineIndexDuty) { //-V547
line_label = "Pulse width";
}
@@ -169,7 +169,7 @@ static void signal_gen_pwm_draw_callback(Canvas* canvas, void* _model) {
canvas_draw_icon(canvas, icon_x, text_y - 9, &I_SmallArrowUp_3x5);
canvas_draw_icon(canvas, icon_x, text_y + 5, &I_SmallArrowDown_3x5);
}
} else if(line == LineIndexDuty) {
} else if(line == LineIndexDuty) { //-V547
snprintf(val_text, sizeof(val_text), "%d%%", model->duty);
canvas_draw_str_aligned(canvas, VALUE_X, text_y, AlignCenter, AlignCenter, val_text);
if(model->duty != 0) {

View File

@@ -130,7 +130,7 @@ static void snake_game_render_callback(Canvas* const canvas, void* ctx) {
canvas_set_font(canvas, FontSecondary);
char buffer[12];
snprintf(buffer, sizeof(buffer), "Score: %u", snake_state->len - 7);
snprintf(buffer, sizeof(buffer), "Score: %u", snake_state->len - 7U);
canvas_draw_str_aligned(canvas, 64, 41, AlignCenter, AlignBottom, buffer);
}
@@ -153,7 +153,7 @@ static void snake_game_update_timer_callback(FuriMessageQueue* event_queue) {
static void snake_game_init_game(SnakeState* const snake_state) {
Point p[] = {{8, 6}, {7, 6}, {6, 6}, {5, 6}, {4, 6}, {3, 6}, {2, 6}};
memcpy(snake_state->points, p, sizeof(p));
memcpy(snake_state->points, p, sizeof(p)); //-V1086
snake_state->len = 7;

View File

@@ -343,7 +343,7 @@ bool ws_protocol_decoder_oregon2_deserialize(void* context, FlipperFormat* flipp
flipper_format,
"VarData",
(uint8_t*)&instance->var_data,
sizeof(instance->var_data))) {
sizeof(instance->var_data))) { //-V1051
FURI_LOG_E(TAG, "Missing VarData");
break;
}

View File

@@ -147,7 +147,7 @@ static void ws_protocol_oregon_v1_remote_controller(WSBlockGeneric* instance) {
instance->temp = -temp_raw;
}
instance->battery_low = !(instance->data >> 23) & 1;
instance->battery_low = !((instance->data >> 23) & 1ULL);
instance->btn = WS_NO_BTN;
instance->humidity = WS_NO_HUMIDITY;

View File

@@ -79,7 +79,7 @@ bool ws_block_generic_serialize(
uint8_t key_data[sizeof(uint64_t)] = {0};
for(size_t i = 0; i < sizeof(uint64_t); i++) {
key_data[sizeof(uint64_t) - i - 1] = (instance->data >> i * 8) & 0xFF;
key_data[sizeof(uint64_t) - i - 1] = (instance->data >> (i * 8)) & 0xFF;
}
if(!flipper_format_write_hex(flipper_format, "Data", key_data, sizeof(uint64_t))) {
@@ -208,4 +208,4 @@ bool ws_block_generic_deserialize(WSBlockGeneric* instance, FlipperFormat* flipp
} while(0);
return res;
}
}

View File

@@ -4,8 +4,7 @@
#include "../protocols/ws_generic.h"
#include <input/input.h>
#include <gui/elements.h>
#define abs(x) ((x) > 0 ? (x) : -(x))
#include <float_tools.h>
struct WSReceiverInfo {
View* view;
@@ -79,7 +78,7 @@ void ws_view_receiver_info_draw(Canvas* canvas, WSReceiverInfoModel* model) {
elements_bold_rounded_frame(canvas, 0, 38, 127, 25);
canvas_set_font(canvas, FontPrimary);
if(model->generic->temp != WS_NO_TEMPERATURE) {
if(!float_is_equal(model->generic->temp, WS_NO_TEMPERATURE)) {
canvas_draw_icon(canvas, 6, 43, &I_Therm_7x16);
uint8_t temp_x1 = 0;

View File

@@ -111,11 +111,8 @@ void ws_hopper_update(WeatherStationApp* app) {
switch(app->txrx->hopper_state) {
case WSHopperStateOFF:
return;
break;
case WSHopperStatePause:
return;
break;
case WSHopperStateRSSITimeOut:
if(app->txrx->hopper_timeout != 0) {
app->txrx->hopper_timeout--;

View File

@@ -186,7 +186,7 @@ WSHistoryStateAddKey
}
// or add new record
if(!sensor_found) {
if(!sensor_found) { //-V547
WSHistoryItem* item = WSHistoryItemArray_push_raw(instance->history->data);
item->preset = malloc(sizeof(SubGhzRadioPreset));
item->type = decoder_base->protocol->type;