[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

@@ -1,4 +1,5 @@
#include "popup_vm.h"
#include "gui/modules/popup.h"
PopupVM::PopupVM() {
popup = popup_alloc();
}
@@ -50,5 +51,5 @@ void PopupVM::enable_timeout() {
}
void PopupVM::disable_timeout() {
popup_enable_timeout(popup);
popup_disable_timeout(popup);
}

View File

@@ -121,7 +121,7 @@ uint32_t cc1101_set_intermediate_frequency(FuriHalSpiBusHandle* handle, uint32_t
}
void cc1101_set_pa_table(FuriHalSpiBusHandle* handle, const uint8_t value[8]) {
uint8_t tx[9] = {CC1101_PATABLE | CC1101_BURST};
uint8_t tx[9] = {CC1101_PATABLE | CC1101_BURST}; //-V1009
CC1101Status rx[9] = {0};
memcpy(&tx[1], &value[0], 8);

View File

@@ -105,7 +105,7 @@ void lp5562_set_channel_src(FuriHalI2cBusHandle* handle, LP5562Channel channel,
reg_val &= ~(0x3 << bit_offset);
reg_val |= ((src & 0x03) << bit_offset);
furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x70, reg_val, LP5562_I2C_TIMEOUT);
} while(channel);
} while(channel != 0);
}
void lp5562_execute_program(
@@ -166,7 +166,7 @@ void lp5562_stop_program(FuriHalI2cBusHandle* handle, LP5562Engine eng) {
bit_offset = (3 - eng) * 2;
furi_hal_i2c_read_reg_8(handle, LP5562_ADDRESS, 0x01, &reg_val, LP5562_I2C_TIMEOUT);
reg_val &= ~(0x3 << bit_offset);
reg_val |= (0x00 << bit_offset); // Disabled
// Not setting lowest 2 bits here
furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x01, reg_val, LP5562_I2C_TIMEOUT);
}

View File

@@ -6,8 +6,8 @@
#define TAG "elf"
#define ELF_NAME_BUFFER_LEN 32
#define SECTION_OFFSET(e, n) (e->section_table + n * sizeof(Elf32_Shdr))
#define IS_FLAGS_SET(v, m) ((v & m) == m)
#define SECTION_OFFSET(e, n) ((e)->section_table + (n) * sizeof(Elf32_Shdr))
#define IS_FLAGS_SET(v, m) (((v) & (m)) == (m))
#define RESOLVER_THREAD_YIELD_STEP 30
// #define ELF_DEBUG_LOG 1
@@ -758,15 +758,13 @@ ELFFileLoadStatus elf_file_load_sections(ELFFile* elf) {
AddressCache_init(elf->relocation_cache);
if(status == ELFFileLoadStatusSuccess) {
for(ELFSectionDict_it(it, elf->sections); !ELFSectionDict_end_p(it);
ELFSectionDict_next(it)) {
ELFSectionDict_itref_t* itref = ELFSectionDict_ref(it);
FURI_LOG_D(TAG, "Relocating section '%s'", itref->key);
if(!elf_relocate_section(elf, &itref->value)) {
FURI_LOG_E(TAG, "Error relocating section '%s'", itref->key);
status = ELFFileLoadStatusMissingImports;
}
for(ELFSectionDict_it(it, elf->sections); !ELFSectionDict_end_p(it);
ELFSectionDict_next(it)) {
ELFSectionDict_itref_t* itref = ELFSectionDict_ref(it);
FURI_LOG_D(TAG, "Relocating section '%s'", itref->key);
if(!elf_relocate_section(elf, &itref->value)) {
FURI_LOG_E(TAG, "Error relocating section '%s'", itref->key);
status = ELFFileLoadStatusMissingImports;
}
}
@@ -793,7 +791,7 @@ ELFFileLoadStatus elf_file_load_sections(ELFFile* elf) {
ELFSectionDict_itref_t* itref = ELFSectionDict_ref(it);
total_size += itref->value.size;
}
FURI_LOG_I(TAG, "Total size of loaded sections: %u", total_size);
FURI_LOG_I(TAG, "Total size of loaded sections: %u", total_size); //-V576
}
return status;

View File

@@ -298,7 +298,7 @@ bool flipper_format_stream_write_value_line(Stream* stream, FlipperStreamWriteDa
}; break;
case FlipperStreamValueUint32: {
const uint32_t* data = write_data->data;
furi_string_printf(value, "%" PRId32, data[i]);
furi_string_printf(value, "%" PRIu32, data[i]);
}; break;
case FlipperStreamValueHexUint64: {
const uint64_t* data = write_data->data;
@@ -396,7 +396,7 @@ bool flipper_format_stream_read_value_line(
}; break;
case FlipperStreamValueUint32: {
uint32_t* data = _data;
scan_values = sscanf(furi_string_get_cstr(value), "%" PRId32, &data[i]);
scan_values = sscanf(furi_string_get_cstr(value), "%" PRIu32, &data[i]);
}; break;
case FlipperStreamValueHexUint64: {
uint64_t* data = _data;

View File

@@ -107,7 +107,7 @@ static InfraredStatus infrared_common_decode_bits(InfraredCommonDecoder* decoder
decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1);
/* check if largest protocol version can be decoded */
if(level && (decoder->protocol->databit_len[0] == decoder->databit_cnt) &&
if(level && (decoder->protocol->databit_len[0] == decoder->databit_cnt) && //-V1051
!timings->min_split_time) {
status = InfraredStatusReady;
break;

View File

@@ -94,7 +94,6 @@ InfraredStatus
case InfraredCommonEncoderStateSilence:
*duration = encoder->protocol->timings.silence_time;
*level = false;
status = InfraredStatusOk;
encoder->state = InfraredCommonEncoderStatePreamble;
++encoder->timings_encoded;
encoder->timings_sum = 0;

View File

@@ -4,7 +4,7 @@
#include "infrared.h"
#include "infrared_i.h"
#define MATCH_TIMING(x, v, delta) (((x) < (v + delta)) && ((x) > (v - delta)))
#define MATCH_TIMING(x, v, delta) (((x) < ((v) + (delta))) && ((x) > ((v) - (delta))))
typedef struct InfraredCommonDecoder InfraredCommonDecoder;
typedef struct InfraredCommonEncoder InfraredCommonEncoder;

View File

@@ -67,7 +67,7 @@ void infrared_send_raw(const uint32_t timings[], uint32_t timings_cnt, bool star
FuriHalInfraredTxGetDataState
infrared_get_data_callback(void* context, uint32_t* duration, bool* level) {
FuriHalInfraredTxGetDataState state = FuriHalInfraredTxGetDataStateLastDone;
FuriHalInfraredTxGetDataState state;
InfraredEncoderHandler* handler = context;
InfraredStatus status = InfraredStatusError;
@@ -82,9 +82,10 @@ FuriHalInfraredTxGetDataState
} else if(status == InfraredStatusOk) {
state = FuriHalInfraredTxGetDataStateOk;
} else if(status == InfraredStatusDone) {
state = FuriHalInfraredTxGetDataStateDone;
if(--infrared_tx_number_of_transmissions == 0) {
state = FuriHalInfraredTxGetDataStateLastDone;
} else {
state = FuriHalInfraredTxGetDataStateDone;
}
} else {
furi_crash(NULL);

View File

@@ -7,6 +7,7 @@
#include <limits.h>
#include <stdint.h>
#include <furi.h>
#include <float_tools.h>
#include <notification/notification_messages.h>
@@ -397,8 +398,9 @@ static bool infrared_get_new_signal(InfraredWorker* instance) {
}
instance->tx.tx_raw_cnt = 0;
instance->tx.need_reinitialization = (new_tx_frequency != instance->tx.frequency) ||
(new_tx_duty_cycle != instance->tx.duty_cycle);
instance->tx.need_reinitialization =
(new_tx_frequency != instance->tx.frequency) ||
!float_is_equal(new_tx_duty_cycle, instance->tx.duty_cycle);
instance->tx.frequency = new_tx_frequency;
instance->tx.duty_cycle = new_tx_duty_cycle;
if(instance->signal.decoded) {

View File

@@ -7,7 +7,7 @@
extern "C" {
#endif
#define MAX_TIMINGS_AMOUNT 1024
#define MAX_TIMINGS_AMOUNT 1024U
/** Interface struct of infrared worker */
typedef struct InfraredWorker InfraredWorker;

View File

@@ -114,7 +114,6 @@ void lfrfid_raw_worker_stop(LFRFIDRawWorker* worker) {
worker->emulate_callback = NULL;
worker->context = NULL;
worker->read_callback = NULL;
worker->context = NULL;
furi_event_flag_set(worker->events, 1 << LFRFIDRawWorkerEventStop);
furi_thread_join(worker->thread);
}
@@ -335,7 +334,7 @@ static int32_t lfrfid_raw_emulate_worker_thread(void* thread_context) {
}
if(data->ctx.overrun_count) {
FURI_LOG_E(TAG_EMULATE, "overruns: %u", data->ctx.overrun_count);
FURI_LOG_E(TAG_EMULATE, "overruns: %zu", data->ctx.overrun_count);
}
furi_stream_buffer_free(data->ctx.stream);
@@ -344,4 +343,4 @@ static int32_t lfrfid_raw_emulate_worker_thread(void* thread_context) {
free(data);
return 0;
}
}

View File

@@ -139,7 +139,7 @@ static int32_t lfrfid_worker_thread(void* thread_context) {
while(true) {
uint32_t flags = furi_thread_flags_wait(LFRFIDEventAll, FuriFlagWaitAny, FuriWaitForever);
if(flags != FuriFlagErrorTimeout) {
if(flags != (unsigned)FuriFlagErrorTimeout) {
// stop thread
if(flags & LFRFIDEventStopThread) break;
@@ -161,4 +161,4 @@ static int32_t lfrfid_worker_thread(void* thread_context) {
}
return 0;
}
}

View File

@@ -276,7 +276,7 @@ static LFRFIDWorkerReadState lfrfid_worker_read_internal(
FURI_LOG_D(
TAG,
"%s, %d, [%s]",
"%s, %zu, [%s]",
protocol_dict_get_name(worker->protocols, protocol),
last_read_count,
furi_string_get_cstr(string_info));
@@ -335,9 +335,9 @@ static LFRFIDWorkerReadState lfrfid_worker_read_internal(
}
static void lfrfid_worker_mode_read_process(LFRFIDWorker* worker) {
LFRFIDFeature feature = LFRFIDFeatureASK;
ProtocolId read_result = PROTOCOL_NO;
LFRFIDWorkerReadState state;
LFRFIDFeature feature;
if(worker->read_type == LFRFIDWorkerReadTypePSKOnly) {
feature = LFRFIDFeaturePSK;
@@ -635,4 +635,4 @@ const LFRFIDWorkerModeType lfrfid_worker_modes[] = {
[LFRFIDWorkerEmulate] = {.process = lfrfid_worker_mode_emulate_process},
[LFRFIDWorkerReadRaw] = {.process = lfrfid_worker_mode_read_raw_process},
[LFRFIDWorkerEmulateRaw] = {.process = lfrfid_worker_mode_emulate_raw_process},
};
};

View File

@@ -353,4 +353,4 @@ const ProtocolBase protocol_indala26 = {
.render_data = (ProtocolRenderData)protocol_indala26_render_data,
.render_brief_data = (ProtocolRenderData)protocol_indala26_render_brief_data,
.write_data = (ProtocolWriteData)protocol_indala26_write_data,
};
};

View File

@@ -12,7 +12,7 @@
#define PAC_STANLEY_ENCODED_BYTE_FULL_SIZE \
(PAC_STANLEY_ENCODED_BYTE_SIZE + PAC_STANLEY_PREAMBLE_BYTE_SIZE)
#define PAC_STANLEY_BYTE_LENGTH (10) // start bit, 7 data bits, parity bit, stop bit
#define PAC_STANLEY_DATA_START_INDEX 8 + (3 * PAC_STANLEY_BYTE_LENGTH) + 1
#define PAC_STANLEY_DATA_START_INDEX (8 + (3 * PAC_STANLEY_BYTE_LENGTH) + 1)
#define PAC_STANLEY_DECODED_DATA_SIZE (4)
#define PAC_STANLEY_ENCODED_DATA_SIZE (sizeof(ProtocolPACStanley))
@@ -128,7 +128,7 @@ bool protocol_pac_stanley_decoder_feed(ProtocolPACStanley* protocol, bool level,
}
bool protocol_pac_stanley_encoder_start(ProtocolPACStanley* protocol) {
memset(protocol->encoded_data, 0, PAC_STANLEY_ENCODED_BYTE_SIZE);
memset(protocol->encoded_data, 0, sizeof(protocol->encoded_data));
uint8_t idbytes[10];
idbytes[0] = '2';
@@ -137,7 +137,7 @@ bool protocol_pac_stanley_encoder_start(ProtocolPACStanley* protocol) {
uint8_to_hex_chars(protocol->data, &idbytes[2], 8);
// insert start and stop bits
for(size_t i = 0; i < 16; i++) protocol->encoded_data[i] = 0x40 >> (i + 3) % 5 * 2;
for(size_t i = 0; i < 16; i++) protocol->encoded_data[i] = 0x40 >> ((i + 3) % 5 * 2);
protocol->encoded_data[0] = 0xFF; // mark + stop
protocol->encoded_data[1] = 0x20; // start + reflect8(STX)
@@ -228,4 +228,4 @@ const ProtocolBase protocol_pac_stanley = {
.render_data = (ProtocolRenderData)protocol_pac_stanley_render_data,
.render_brief_data = (ProtocolRenderData)protocol_pac_stanley_render_data,
.write_data = (ProtocolWriteData)protocol_pac_stanley_write_data,
};
};

View File

@@ -25,7 +25,7 @@ void bit_lib_set_bits(uint8_t* data, size_t position, uint8_t byte, uint8_t leng
for(uint8_t i = 0; i < length; ++i) {
uint8_t shift = (length - 1) - i;
bit_lib_set_bit(data, position + i, (byte >> shift) & 1);
bit_lib_set_bit(data, position + i, (byte >> shift) & 1); //-V610
}
}
@@ -69,9 +69,9 @@ uint32_t bit_lib_get_bits_32(const uint8_t* data, size_t position, uint8_t lengt
value |= bit_lib_get_bits(data, position + 8, 8) << (length - 16);
value |= bit_lib_get_bits(data, position + 16, length - 16);
} else {
value = bit_lib_get_bits(data, position, 8) << (length - 8);
value |= bit_lib_get_bits(data, position + 8, 8) << (length - 16);
value |= bit_lib_get_bits(data, position + 16, 8) << (length - 24);
value = (uint32_t)bit_lib_get_bits(data, position, 8) << (length - 8);
value |= (uint32_t)bit_lib_get_bits(data, position + 8, 8) << (length - 16);
value |= (uint32_t)bit_lib_get_bits(data, position + 16, 8) << (length - 24);
value |= bit_lib_get_bits(data, position + 24, length - 24);
}
@@ -364,4 +364,4 @@ uint16_t bit_lib_crc16(
crc ^= xor_out;
return crc;
}
}

View File

@@ -7,7 +7,7 @@
extern "C" {
#endif
#define TOPBIT(X) (1 << (X - 1))
#define TOPBIT(X) (1 << ((X)-1))
typedef enum {
BitLibParityEven,
@@ -26,13 +26,13 @@ typedef enum {
* @param data value to test
* @param index bit index to test
*/
#define bit_lib_bit_is_set(data, index) ((data & (1 << (index))) != 0)
#define bit_lib_bit_is_set(data, index) (((data) & (1 << (index))) != 0)
/** @brief Test if a bit is not set.
* @param data value to test
* @param index bit index to test
*/
#define bit_lib_bit_is_not_set(data, index) ((data & (1 << (index))) == 0)
#define bit_lib_bit_is_not_set(data, index) (((data) & (1 << (index))) == 0)
/** @brief Push a bit into a byte array.
* @param data array to push bit into
@@ -269,4 +269,4 @@ uint16_t bit_lib_crc16(
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -28,11 +28,9 @@ bool varint_pair_pack(VarintPair* pair, bool first, uint32_t value) {
pair->data_length = 0;
}
} else {
if(pair->data_length > 0) {
if(pair->data_length != 0) {
pair->data_length += varint_uint32_pack(value, pair->data + pair->data_length);
result = true;
} else {
pair->data_length = 0;
}
}

View File

@@ -90,7 +90,7 @@ MfClassicDict* mf_classic_dict_alloc(MfClassicDictType dict_type) {
}
FURI_LOG_T(
TAG,
"Read line: %s, len: %d",
"Read line: %s, len: %zu",
furi_string_get_cstr(next_line),
furi_string_size(next_line));
if(furi_string_get_char(next_line, 0) == '#') continue;
@@ -101,7 +101,7 @@ MfClassicDict* mf_classic_dict_alloc(MfClassicDictType dict_type) {
stream_rewind(dict->stream);
dict_loaded = true;
FURI_LOG_I(TAG, "Loaded dictionary with %ld keys", dict->total_keys);
FURI_LOG_I(TAG, "Loaded dictionary with %lu keys", dict->total_keys);
} while(false);
if(!dict_loaded) {
@@ -136,7 +136,7 @@ static void mf_classic_dict_str_to_int(FuriString* key_str, uint64_t* key_int) {
for(uint8_t i = 0; i < 12; i += 2) {
args_char_to_hex(
furi_string_get_char(key_str, i), furi_string_get_char(key_str, i + 1), &key_byte_tmp);
*key_int |= (uint64_t)key_byte_tmp << 8 * (5 - i / 2);
*key_int |= (uint64_t)key_byte_tmp << (8 * (5 - i / 2));
}
}
@@ -193,7 +193,7 @@ bool mf_classic_dict_is_key_present_str(MfClassicDict* dict, FuriString* key) {
bool key_found = false;
stream_rewind(dict->stream);
while(!key_found) {
while(!key_found) { //-V654
if(!stream_read_line(dict->stream, next_line)) break;
if(furi_string_get_char(next_line, 0) == '#') continue;
if(furi_string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
@@ -294,7 +294,7 @@ bool mf_classic_dict_find_index_str(MfClassicDict* dict, FuriString* key, uint32
bool key_found = false;
uint32_t index = 0;
stream_rewind(dict->stream);
while(!key_found) {
while(!key_found) { //-V654
if(!stream_read_line(dict->stream, next_line)) break;
if(furi_string_get_char(next_line, 0) == '#') continue;
if(furi_string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;

View File

@@ -221,11 +221,11 @@ static void reader_analyzer_write(
data_sent = furi_stream_buffer_send(
instance->stream, &header, sizeof(ReaderAnalyzerHeader), FuriWaitForever);
if(data_sent != sizeof(ReaderAnalyzerHeader)) {
FURI_LOG_W(TAG, "Sent %d out of %d bytes", data_sent, sizeof(ReaderAnalyzerHeader));
FURI_LOG_W(TAG, "Sent %zu out of %zu bytes", data_sent, sizeof(ReaderAnalyzerHeader));
}
data_sent = furi_stream_buffer_send(instance->stream, data, len, FuriWaitForever);
if(data_sent != len) {
FURI_LOG_W(TAG, "Sent %d out of %d bytes", data_sent, len);
FURI_LOG_W(TAG, "Sent %zu out of %u bytes", data_sent, len);
}
}

View File

@@ -576,7 +576,7 @@ static bool nfc_device_save_mifare_df_data(FlipperFormat* file, NfcDevice* dev)
tmp = malloc(n_apps * 3);
int i = 0;
for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
memcpy(tmp + i, app->id, 3);
memcpy(tmp + i, app->id, 3); //-V769
i += 3;
}
if(!flipper_format_write_hex(file, "Application IDs", tmp, n_apps * 3)) break;
@@ -1085,7 +1085,7 @@ bool nfc_device_save(NfcDevice* dev, const char* dev_name) {
saved = true;
} while(0);
if(!saved) {
if(!saved) { //-V547
dialog_message_show_storage_error(dev->dialogs, "Can not save\nkey file");
}
furi_string_free(temp_str);

View File

@@ -453,11 +453,11 @@ void nfc_worker_read_type(NfcWorker* nfc_worker) {
event = NfcWorkerEventReadUidNfcA;
break;
}
} else {
if(!card_not_detected_notified) {
nfc_worker->callback(NfcWorkerEventNoCardDetected, nfc_worker->context);
card_not_detected_notified = true;
}
}
} else {
if(!card_not_detected_notified) {
nfc_worker->callback(NfcWorkerEventNoCardDetected, nfc_worker->context);
card_not_detected_notified = true;
}
}
furi_hal_nfc_sleep();
@@ -509,7 +509,7 @@ void nfc_worker_emulate_apdu(NfcWorker* nfc_worker) {
reader_analyzer_start(nfc_worker->reader_analyzer, ReaderAnalyzerModeDebugLog);
}
while(nfc_worker->state == NfcWorkerStateEmulateApdu) {
while(nfc_worker->state == NfcWorkerStateEmulateApdu) { //-V1044
if(furi_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, false, 300)) {
FURI_LOG_D(TAG, "POS terminal detected");
if(emv_card_emulation(&tx_rx)) {
@@ -657,7 +657,7 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) {
}
FURI_LOG_D(
TAG, "Start Dictionary attack, Key Count %ld", mf_classic_dict_get_total_keys(dict));
TAG, "Start Dictionary attack, Key Count %lu", mf_classic_dict_get_total_keys(dict));
for(size_t i = 0; i < total_sectors; i++) {
FURI_LOG_I(TAG, "Sector %d", i);
nfc_worker->callback(NfcWorkerEventNewSector, nfc_worker->context);
@@ -742,7 +742,7 @@ void nfc_worker_emulate_mf_classic(NfcWorker* nfc_worker) {
rfal_platform_spi_acquire();
furi_hal_nfc_listen_start(nfc_data);
while(nfc_worker->state == NfcWorkerStateMfClassicEmulate) {
while(nfc_worker->state == NfcWorkerStateMfClassicEmulate) { //-V1044
if(furi_hal_nfc_listen_rx(&tx_rx, 300)) {
mf_classic_emulator(&emulator, &tx_rx);
}
@@ -776,7 +776,8 @@ void nfc_worker_write_mf_classic(NfcWorker* nfc_worker) {
furi_hal_nfc_sleep();
FURI_LOG_I(TAG, "Check low level nfc data");
if(memcmp(&nfc_data, &nfc_worker->dev_data->nfc_data, sizeof(FuriHalNfcDevData))) {
if(memcmp(&nfc_data, &nfc_worker->dev_data->nfc_data, sizeof(FuriHalNfcDevData)) !=
0) {
FURI_LOG_E(TAG, "Wrong card");
nfc_worker->callback(NfcWorkerEventWrongCard, nfc_worker->context);
break;
@@ -848,7 +849,8 @@ void nfc_worker_update_mf_classic(NfcWorker* nfc_worker) {
furi_hal_nfc_sleep();
FURI_LOG_I(TAG, "Check low level nfc data");
if(memcmp(&nfc_data, &nfc_worker->dev_data->nfc_data, sizeof(FuriHalNfcDevData))) {
if(memcmp(&nfc_data, &nfc_worker->dev_data->nfc_data, sizeof(FuriHalNfcDevData)) !=
0) {
FURI_LOG_E(TAG, "Low level nfc data mismatch");
nfc_worker->callback(NfcWorkerEventWrongCard, nfc_worker->context);
break;

View File

@@ -73,24 +73,14 @@ bool all_in_one_parser_parse(NfcDeviceData* dev_data) {
return false;
}
// If the layout is a then the ride count is stored in the first byte of page 8
uint8_t ride_count = 0;
uint32_t serial = 0;
if(all_in_one_get_layout(dev_data) == ALL_IN_ONE_LAYOUT_A) {
// If the layout is A then the ride count is stored in the first byte of page 8
ride_count = dev_data->mf_ul_data.data[4 * 8];
} else if(all_in_one_get_layout(dev_data) == ALL_IN_ONE_LAYOUT_D) {
// If the layout is D, the ride count is stored in the second byte of page 9
ride_count = dev_data->mf_ul_data.data[4 * 9 + 1];
// I hate this with a burning passion.
// The number starts at the second half of the third byte on page 4, and is 32 bits long
// So we get the second half of the third byte, then bytes 4-6, and then the first half of the 7th byte
// B8 17 A2 A4 BD becomes 81 7A 2A 4B
serial = (dev_data->mf_ul_data.data[4 * 4 + 2] & 0x0F) << 28 |
dev_data->mf_ul_data.data[4 * 4 + 3] << 20 |
dev_data->mf_ul_data.data[4 * 4 + 4] << 12 |
dev_data->mf_ul_data.data[4 * 4 + 5] << 4 |
(dev_data->mf_ul_data.data[4 * 4 + 6] >> 4);
} else {
FURI_LOG_I("all_in_one", "Unknown layout: %d", all_in_one_get_layout(dev_data));
ride_count = 137;
@@ -110,4 +100,4 @@ bool all_in_one_parser_parse(NfcDeviceData* dev_data) {
furi_string_printf(
dev_data->parsed_data, "\e#All-In-One\nNumber: %lu\nRides left: %u", serial, ride_count);
return true;
}
}

View File

@@ -116,26 +116,9 @@ bool plantain_4k_parser_parse(NfcDeviceData* dev_data) {
for(size_t i = 0; i < 7; i++) {
card_number = (card_number << 8) | card_number_arr[i];
}
// Convert card number to string
FuriString* card_number_str;
card_number_str = furi_string_alloc();
// Should look like "361301047292848684"
furi_string_printf(card_number_str, "%llu", card_number);
// Add suffix with luhn checksum (1 digit) to the card number string
FuriString* card_number_suffix;
card_number_suffix = furi_string_alloc();
furi_string_cat_printf(card_number_suffix, "-");
furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix));
// Free all not needed strings
furi_string_free(card_number_suffix);
furi_string_printf(
dev_data->parsed_data,
"\e#Plantain\nN:%s\nBalance:%ld\n",
furi_string_get_cstr(card_number_str),
balance);
furi_string_free(card_number_str);
dev_data->parsed_data, "\e#Plantain\nN:%llu-\nBalance:%ld\n", card_number, balance);
return true;
}

View File

@@ -89,26 +89,9 @@ bool plantain_parser_parse(NfcDeviceData* dev_data) {
for(size_t i = 0; i < 7; i++) {
card_number = (card_number << 8) | card_number_arr[i];
}
// Convert card number to string
FuriString* card_number_str;
card_number_str = furi_string_alloc();
// Should look like "361301047292848684"
furi_string_printf(card_number_str, "%llu", card_number);
// Add suffix with luhn checksum (1 digit) to the card number string
FuriString* card_number_suffix;
card_number_suffix = furi_string_alloc();
furi_string_cat_printf(card_number_suffix, "-");
furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix));
// Free all not needed strings
furi_string_free(card_number_suffix);
furi_string_printf(
dev_data->parsed_data,
"\e#Plantain\nN:%s\nBalance:%ld\n",
furi_string_get_cstr(card_number_str),
balance);
furi_string_free(card_number_str);
dev_data->parsed_data, "\e#Plantain\nN:%llu-\nBalance:%ld\n", card_number, balance);
return true;
}

View File

@@ -117,19 +117,6 @@ bool two_cities_parser_parse(NfcDeviceData* dev_data) {
for(size_t i = 0; i < 7; i++) {
card_number = (card_number << 8) | card_number_arr[i];
}
// Convert card number to string
FuriString* card_number_str;
card_number_str = furi_string_alloc();
// Should look like "361301047292848684"
furi_string_printf(card_number_str, "%llu", card_number);
// Add suffix with luhn checksum (1 digit) to the card number string
FuriString* card_number_suffix;
card_number_suffix = furi_string_alloc();
furi_string_cat_printf(card_number_suffix, "-");
furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix));
// Free all not needed strings
furi_string_free(card_number_suffix);
// =====
// --PLANTAIN--
@@ -149,12 +136,11 @@ bool two_cities_parser_parse(NfcDeviceData* dev_data) {
furi_string_printf(
dev_data->parsed_data,
"\e#Troika+Plantain\nPN: %s\nPB: %ld rur.\nTN: %ld\nTB: %d rur.\n",
furi_string_get_cstr(card_number_str),
"\e#Troika+Plantain\nPN: %llu-\nPB: %ld rur.\nTN: %ld\nTB: %d rur.\n",
card_number,
balance,
troika_number,
troika_balance);
furi_string_free(card_number_str);
return true;
}

View File

@@ -4,7 +4,8 @@
// Algorithm from https://github.com/RfidResearchGroup/proxmark3.git
#define SWAPENDIAN(x) (x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16)
#define SWAPENDIAN(x) \
((x) = ((x) >> 8 & 0xff00ff) | ((x)&0xff00ff) << 8, (x) = (x) >> 16 | (x) << 16)
#define LF_POLY_ODD (0x29CE5C)
#define LF_POLY_EVEN (0x870804)

View File

@@ -245,7 +245,8 @@ bool mf_classic_is_allowed_access_sector_trailer(
case MfClassicActionKeyARead: {
return false;
}
case MfClassicActionKeyAWrite: {
case MfClassicActionKeyAWrite:
case MfClassicActionKeyBWrite: {
return (
(key == MfClassicKeyA && (AC == 0x00 || AC == 0x01)) ||
(key == MfClassicKeyB && (AC == 0x04 || AC == 0x03)));
@@ -253,11 +254,6 @@ bool mf_classic_is_allowed_access_sector_trailer(
case MfClassicActionKeyBRead: {
return (key == MfClassicKeyA && (AC == 0x00 || AC == 0x02 || AC == 0x01));
}
case MfClassicActionKeyBWrite: {
return (
(key == MfClassicKeyA && (AC == 0x00 || AC == 0x01)) ||
(key == MfClassicKeyB && (AC == 0x04 || AC == 0x03)));
}
case MfClassicActionACRead: {
return (
(key == MfClassicKeyA) ||
@@ -734,7 +730,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
MfClassicKey access_key = MfClassicKeyA;
// Read command
while(!command_processed) {
while(!command_processed) { //-V654
if(!is_encrypted) {
crypto1_reset(&emulator->crypto);
memcpy(plain_data, tx_rx->rx_data, tx_rx->rx_bits / 8);
@@ -850,7 +846,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
if(mf_classic_is_sector_trailer(block)) {
if(!mf_classic_is_allowed_access(
emulator, block, access_key, MfClassicActionKeyARead)) {
memset(block_data, 0, 6);
memset(block_data, 0, 6); //-V1086
}
if(!mf_classic_is_allowed_access(
emulator, block, access_key, MfClassicActionKeyBRead)) {
@@ -860,22 +856,16 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
emulator, block, access_key, MfClassicActionACRead)) {
memset(&block_data[6], 0, 4);
}
} else {
if(!mf_classic_is_allowed_access(
emulator, block, access_key, MfClassicActionDataRead)) {
// Send NACK
uint8_t nack = 0x04;
if(is_encrypted) {
crypto1_encrypt(
&emulator->crypto, NULL, &nack, 4, tx_rx->tx_data, tx_rx->tx_parity);
} else {
tx_rx->tx_data[0] = nack;
}
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
tx_rx->tx_bits = 4;
furi_hal_nfc_tx_rx(tx_rx, 300);
break;
}
} else if(!mf_classic_is_allowed_access(
emulator, block, access_key, MfClassicActionDataRead)) {
// Send NACK
uint8_t nack = 0x04;
crypto1_encrypt(
&emulator->crypto, NULL, &nack, 4, tx_rx->tx_data, tx_rx->tx_parity);
tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent;
tx_rx->tx_bits = 4;
furi_hal_nfc_tx_rx(tx_rx, 300);
break;
}
nfca_append_crc16(block_data, 16);
@@ -908,7 +898,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
if(mf_classic_is_sector_trailer(block)) {
if(mf_classic_is_allowed_access(
emulator, block, access_key, MfClassicActionKeyAWrite)) {
memcpy(block_data, plain_data, 6);
memcpy(block_data, plain_data, 6); //-V1086
}
if(mf_classic_is_allowed_access(
emulator, block, access_key, MfClassicActionKeyBWrite)) {
@@ -924,7 +914,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_
memcpy(block_data, plain_data, MF_CLASSIC_BLOCK_SIZE);
}
}
if(memcmp(block_data, emulator->data.block[block].value, MF_CLASSIC_BLOCK_SIZE)) {
if(memcmp(block_data, emulator->data.block[block].value, MF_CLASSIC_BLOCK_SIZE) != 0) {
memcpy(emulator->data.block[block].value, block_data, MF_CLASSIC_BLOCK_SIZE);
emulator->data_changed = true;
}
@@ -1060,7 +1050,8 @@ bool mf_classic_write_sector(
bool write_success = true;
for(size_t i = first_block; i < first_block + total_blocks; i++) {
// Compare blocks
if(memcmp(dest_data->block[i].value, src_data->block[i].value, MF_CLASSIC_BLOCK_SIZE)) {
if(memcmp(dest_data->block[i].value, src_data->block[i].value, MF_CLASSIC_BLOCK_SIZE) !=
0) {
bool key_a_write_allowed = mf_classic_is_allowed_access_data_block(
dest_data, i, MfClassicKeyA, MfClassicActionDataWrite);
bool key_b_write_allowed = mf_classic_is_allowed_access_data_block(

View File

@@ -108,7 +108,7 @@ void mf_df_cat_version(MifareDesfireVersion* version, FuriString* out) {
}
void mf_df_cat_free_mem(MifareDesfireFreeMemory* free_mem, FuriString* out) {
furi_string_cat_printf(out, "freeMem %ld\n", free_mem->bytes);
furi_string_cat_printf(out, "freeMem %lu\n", free_mem->bytes);
}
void mf_df_cat_key_settings(MifareDesfireKeySettings* ks, FuriString* out) {
@@ -191,10 +191,10 @@ void mf_df_cat_file(MifareDesfireFile* file, FuriString* out) {
case MifareDesfireFileTypeValue:
size = 4;
furi_string_cat_printf(
out, "lo %ld hi %ld\n", file->settings.value.lo_limit, file->settings.value.hi_limit);
out, "lo %lu hi %lu\n", file->settings.value.lo_limit, file->settings.value.hi_limit);
furi_string_cat_printf(
out,
"limit %ld enabled %d\n",
"limit %lu enabled %d\n",
file->settings.value.limited_credit_value,
file->settings.value.limited_credit_enabled);
break;
@@ -203,7 +203,7 @@ void mf_df_cat_file(MifareDesfireFile* file, FuriString* out) {
size = file->settings.record.size;
num = file->settings.record.cur;
furi_string_cat_printf(out, "size %d\n", size);
furi_string_cat_printf(out, "num %d max %ld\n", num, file->settings.record.max);
furi_string_cat_printf(out, "num %d max %lu\n", num, file->settings.record.max);
break;
}
uint8_t* data = file->contents;
@@ -220,8 +220,9 @@ void mf_df_cat_file(MifareDesfireFile* file, FuriString* out) {
}
}
for(int i = 0; i < 4 && ch + i < size; i++) {
if(isprint(data[rec * size + ch + i])) {
furi_string_cat_printf(out, "%c", data[rec * size + ch + i]);
const size_t data_index = rec * size + ch + i;
if(isprint(data[data_index])) {
furi_string_cat_printf(out, "%c", data[data_index]);
} else {
furi_string_cat_printf(out, ".");
}
@@ -547,7 +548,8 @@ bool mf_df_read_card(FuriHalNfcTxRxContext* tx_rx, MifareDesfireData* data) {
for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
tx_rx->tx_bits = 8 * mf_df_prepare_select_application(tx_rx->tx_data, app->id);
if(!furi_hal_nfc_tx_rx_full(tx_rx) ||
!mf_df_parse_select_application_response(tx_rx->rx_data, tx_rx->rx_bits / 8)) {
!mf_df_parse_select_application_response(
tx_rx->rx_data, tx_rx->rx_bits / 8)) { //-V1051
FURI_LOG_W(TAG, "Bad exchange selecting application");
continue;
}

View File

@@ -170,6 +170,7 @@ bool mf_ultralight_read_version(
}
bool mf_ultralight_authenticate(FuriHalNfcTxRxContext* tx_rx, uint32_t key, uint16_t* pack) {
furi_assert(pack);
bool authenticated = false;
do {
@@ -189,9 +190,7 @@ bool mf_ultralight_authenticate(FuriHalNfcTxRxContext* tx_rx, uint32_t key, uint
break;
}
if(pack != NULL) {
*pack = (tx_rx->rx_data[1] << 8) | tx_rx->rx_data[0];
}
*pack = (tx_rx->rx_data[1] << 8) | tx_rx->rx_data[0];
FURI_LOG_I(TAG, "Auth success. Password: %08lX. PACK: %04X", key, *pack);
authenticated = true;
@@ -492,7 +491,7 @@ MfUltralightConfigPages* mf_ultralight_get_config_pages(MfUltralightData* data)
} else if(
data->type >= MfUltralightTypeNTAGI2CPlus1K &&
data->type <= MfUltralightTypeNTAGI2CPlus2K) {
return (MfUltralightConfigPages*)&data->data[0xe3 * 4];
return (MfUltralightConfigPages*)&data->data[0xe3 * 4]; //-V641
} else {
return NULL;
}
@@ -561,7 +560,7 @@ bool mf_ultralight_read_pages_direct(
FURI_LOG_D(TAG, "Failed to read pages %d - %d", start_index, start_index + 3);
return false;
}
memcpy(data, tx_rx->rx_data, 16);
memcpy(data, tx_rx->rx_data, 16); //-V1086
return true;
}
@@ -584,7 +583,8 @@ bool mf_ultralight_read_pages(
curr_sector_index = tag_sector;
}
FURI_LOG_D(TAG, "Reading pages %d - %d", i, i + (valid_pages > 4 ? 4 : valid_pages) - 1);
FURI_LOG_D(
TAG, "Reading pages %zu - %zu", i, i + (valid_pages > 4 ? 4 : valid_pages) - 1U);
tx_rx->tx_data[0] = MF_UL_READ_CMD;
tx_rx->tx_data[1] = tag_page;
tx_rx->tx_bits = 16;
@@ -593,9 +593,9 @@ bool mf_ultralight_read_pages(
if(!furi_hal_nfc_tx_rx(tx_rx, 50) || tx_rx->rx_bits < 16 * 8) {
FURI_LOG_D(
TAG,
"Failed to read pages %d - %d",
"Failed to read pages %zu - %zu",
i,
i + (valid_pages > 4 ? 4 : valid_pages) - 1);
i + (valid_pages > 4 ? 4 : valid_pages) - 1U);
break;
}
@@ -857,7 +857,7 @@ static void mf_ul_ntag_i2c_fill_cross_area_read(
}
if(apply) {
while(tx_page_offset < 0 && page_length > 0) {
while(tx_page_offset < 0 && page_length > 0) { //-V614
++tx_page_offset;
++data_page_offset;
--page_length;
@@ -987,9 +987,9 @@ static bool mf_ul_check_lock(MfUltralightEmulator* emulator, int16_t write_page)
switch(emulator->data.type) {
// low byte LSB range, MSB range
case MfUltralightTypeNTAG203:
if(write_page >= 16 && write_page <= 27)
if(write_page >= 16 && write_page <= 27) //-V560
shift = (write_page - 16) / 4 + 1;
else if(write_page >= 28 && write_page <= 39)
else if(write_page >= 28 && write_page <= 39) //-V560
shift = (write_page - 28) / 4 + 5;
else if(write_page == 41)
shift = 12;
@@ -1216,7 +1216,7 @@ static void mf_ul_emulate_write(
page_buff[0] = new_locks & 0xff;
page_buff[1] = new_locks >> 8;
page_buff[2] = new_block_locks;
if(emulator->data.type >= MfUltralightTypeUL21 &&
if(emulator->data.type >= MfUltralightTypeUL21 && //-V1016
emulator->data.type <= MfUltralightTypeNTAG216)
page_buff[3] = MF_UL_TEARING_FLAG_DEFAULT;
else

View File

@@ -62,8 +62,6 @@ const char* ibutton_key_get_string_by_type(iButtonKeyType key_type) {
break;
default:
furi_crash("Invalid iButton type");
return "";
break;
}
}

View File

@@ -130,7 +130,6 @@ bool ibutton_worker_read_comparator(iButtonWorker* worker) {
ibutton_key_set_data(worker->key_p, worker->key_data, ibutton_key_get_max_size());
result = true;
break;
break;
default:
break;
}

View File

@@ -72,7 +72,7 @@ static bool writer_write_TM2004(iButtonWriter* writer, iButtonKey* key) {
writer_write_one_bit(writer, 1, 50000);
// read written key byte
answer = onewire_host_read(writer->host);
answer = onewire_host_read(writer->host); //-V519
// check that written and read are same
if(ibutton_key_get_data_p(key)[i] != answer) {

View File

@@ -270,10 +270,10 @@ static LevelDuration protocol_cyfral_encoder_yield(ProtocolCyfral* proto) {
// start word (0b0001)
switch(proto->encoder.index) {
case 0:
result = level_duration_make(false, CYFRAL_0_LOW);
result = level_duration_make(false, CYFRAL_0_LOW); //-V1037
break;
case 1:
result = level_duration_make(true, CYFRAL_0_HI);
result = level_duration_make(true, CYFRAL_0_HI); //-V1037
break;
case 2:
result = level_duration_make(false, CYFRAL_0_LOW);
@@ -341,4 +341,4 @@ const ProtocolBase protocol_cyfral = {
.start = (ProtocolEncoderStart)protocol_cyfral_encoder_start,
.yield = (ProtocolEncoderYield)protocol_cyfral_encoder_yield,
},
};
};

View File

@@ -248,14 +248,14 @@ static LevelDuration protocol_metakom_encoder_yield(ProtocolMetakom* proto) {
if(proto->encoder.index == 0) {
// sync bit
result = level_duration_make(false, METAKOM_PERIOD);
} else if(proto->encoder.index >= 1 && proto->encoder.index <= 6) {
} else if(proto->encoder.index <= 6) {
// start word (0b010)
switch(proto->encoder.index) {
case 1:
result = level_duration_make(true, METAKOM_0_LOW);
result = level_duration_make(true, METAKOM_0_LOW); //-V1037
break;
case 2:
result = level_duration_make(false, METAKOM_0_HI);
result = level_duration_make(false, METAKOM_0_HI); //-V1037
break;
case 3:
result = level_duration_make(true, METAKOM_1_LOW);
@@ -317,4 +317,4 @@ const ProtocolBase protocol_metakom = {
.start = (ProtocolEncoderStart)protocol_metakom_encoder_start,
.yield = (ProtocolEncoderYield)protocol_metakom_encoder_yield,
},
};
};

View File

@@ -41,7 +41,7 @@ uint32_t onewire_slave_wait_while_gpio_is(OneWireSlave* bus, uint32_t time, cons
uint32_t time_ticks = time * furi_hal_cortex_instructions_per_microsecond();
uint32_t time_captured;
do {
do { //-V1044
time_captured = DWT->CYCCNT;
if(furi_hal_ibutton_pin_get_level() != pin_value) {
uint32_t remaining_time = time_ticks - (time_captured - start);
@@ -155,8 +155,10 @@ bool onewire_slave_receive_and_process_cmd(OneWireSlave* bus) {
uint8_t cmd;
onewire_slave_receive(bus, &cmd, 1);
if(bus->error == RESET_IN_PROGRESS) return true;
if(bus->error != NO_ERROR) return false;
if(bus->error == RESET_IN_PROGRESS)
return true;
else if(bus->error != NO_ERROR)
return false;
switch(cmd) {
case 0xF0:
@@ -172,10 +174,8 @@ bool onewire_slave_receive_and_process_cmd(OneWireSlave* bus) {
default: // Unknown command
bus->error = INCORRECT_ONEWIRE_CMD;
return false;
}
if(bus->error == RESET_IN_PROGRESS) return true;
return (bus->error == NO_ERROR);
}
bool onewire_slave_bus_start(OneWireSlave* bus) {

View File

@@ -541,7 +541,7 @@ static size_t _etoa(
exp2 = (int)(expval * 3.321928094887362 + 0.5);
const double z = expval * 2.302585092994046 - exp2 * 0.6931471805599453;
const double z2 = z * z;
conv.U = ((uint64_t)exp2 + 1023) << 52U;
conv.U = ((uint64_t)exp2 + 1023) << 52U; //-V519
// compute exp(z) using continued fractions, see https://en.wikipedia.org/wiki/Exponential_function#Continued_fractions_for_ex
conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + (z2 / (10 + z2 / 14)))));
// correct for rounding errors

View File

@@ -71,7 +71,7 @@ bool subghz_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, "Key", key_data, sizeof(uint64_t))) {

View File

@@ -8,8 +8,7 @@
#define bit_set(value, bit) ((value) |= (1UL << (bit)))
#define bit_clear(value, bit) ((value) &= ~(1UL << (bit)))
#define bit_write(value, bit, bitvalue) (bitvalue ? bit_set(value, bit) : bit_clear(value, bit))
#define DURATION_DIFF(x, y) ((x < y) ? (y - x) : (x - y))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define DURATION_DIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y)))
#ifdef __cplusplus
extern "C" {

View File

@@ -242,7 +242,6 @@ void subghz_protocol_decoder_bett_feed(void* context, bool level, uint32_t durat
if(!level) {
if(DURATION_DIFF(duration, subghz_protocol_bett_const.te_short * 44) <
(subghz_protocol_bett_const.te_delta * 15)) {
instance->decoder.parser_step = BETTDecoderStepSaveDuration;
if(instance->decoder.decode_count_bit ==
subghz_protocol_bett_const.min_count_bit_for_found) {
instance->generic.data = instance->decoder.decode_data;

View File

@@ -240,7 +240,6 @@ void subghz_protocol_decoder_holtek_feed(void* context, bool level, uint32_t dur
if(!level) {
if(duration >= ((uint32_t)subghz_protocol_holtek_const.te_short * 10 +
subghz_protocol_holtek_const.te_delta)) {
instance->decoder.parser_step = HoltekDecoderStepSaveDuration;
if(instance->decoder.decode_count_bit ==
subghz_protocol_holtek_const.min_count_bit_for_found) {
if((instance->decoder.decode_data & HOLTEK_HEADER_MASK) == HOLTEK_HEADER) {

View File

@@ -119,8 +119,8 @@ void subghz_protocol_encoder_keeloq_free(void* context) {
*/
static bool subghz_protocol_keeloq_gen_data(SubGhzProtocolEncoderKeeloq* instance, uint8_t btn) {
instance->generic.cnt++;
uint32_t fix = btn << 28 | instance->generic.serial;
uint32_t decrypt = btn << 28 |
uint32_t fix = (uint32_t)btn << 28 | instance->generic.serial;
uint32_t decrypt = (uint32_t)btn << 28 |
(instance->generic.serial & 0x3FF)
<< 16 | //ToDo in some protocols the discriminator is 0
instance->generic.cnt;
@@ -271,7 +271,8 @@ bool subghz_protocol_encoder_keeloq_deserialize(void* context, FlipperFormat* fl
subghz_protocol_keeloq_check_remote_controller(
&instance->generic, instance->keystore, &instance->manufacture_name);
if(strcmp(instance->manufacture_name, "DoorHan")) {
if(strcmp(instance->manufacture_name, "DoorHan") != 0) {
FURI_LOG_E(TAG, "Wrong manufacturer name");
break;
}
@@ -287,7 +288,7 @@ bool subghz_protocol_encoder_keeloq_deserialize(void* context, FlipperFormat* fl
}
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->generic.data >> i * 8) & 0xFF;
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> (i * 8)) & 0xFF;
}
if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
FURI_LOG_E(TAG, "Unable to add Key");

View File

@@ -142,7 +142,7 @@ void subghz_protocol_decoder_kia_feed(void* context, bool level, uint32_t durati
case KIADecoderStepSaveDuration:
if(level) {
if(duration >=
(uint32_t)(subghz_protocol_kia_const.te_long + subghz_protocol_kia_const.te_delta * 2)) {
(subghz_protocol_kia_const.te_long + subghz_protocol_kia_const.te_delta * 2UL)) {
//Found stop bit
instance->decoder.parser_step = KIADecoderStepReset;
if(instance->decoder.decode_count_bit ==

View File

@@ -417,7 +417,7 @@ void subghz_protocol_decoder_megacode_get_string(void* context, FuriString* outp
output,
"%s %dbit\r\n"
"Key:0x%06lX\r\n"
"Sn:0x%04lX - %ld\r\n"
"Sn:0x%04lX - %lu\r\n"
"Facility:%lX Btn:%X\r\n",
instance->generic.protocol_name,
instance->generic.data_count_bit,

View File

@@ -308,7 +308,7 @@ void subghz_protocol_decoder_nero_radio_feed(void* context, bool level, uint32_t
}
instance->decoder.decode_data = 0;
instance->decoder.decode_count_bit = 0;
instance->decoder.parser_step = NeroRadioDecoderStepReset;
instance->decoder.parser_step = NeroRadioDecoderStepReset; //-V1048
break;
} else if(
(DURATION_DIFF(

View File

@@ -363,7 +363,7 @@ void subghz_protocol_decoder_princeton_get_string(void* context, FuriString* out
"Key:0x%08lX\r\n"
"Yek:0x%08lX\r\n"
"Sn:0x%05lX Btn:%01X\r\n"
"Te:%ldus\r\n",
"Te:%luus\r\n",
instance->generic.protocol_name,
instance->generic.data_count_bit,
(uint32_t)(instance->generic.data & 0xFFFFFF),

View File

@@ -94,12 +94,12 @@ void subghz_encoder_princeton_for_testing_print_log(void* context) {
((float)instance->time_high / (instance->time_high + instance->time_low)) * 100;
FURI_LOG_I(
TAG "Encoder",
"Radio tx_time=%ldus ON=%ldus, OFF=%ldus, DutyCycle=%ld,%ld%%",
"Radio tx_time=%luus ON=%luus, OFF=%luus, DutyCycle=%lu,%lu%%",
instance->time_high + instance->time_low,
instance->time_high,
instance->time_low,
(uint32_t)duty_cycle,
(uint32_t)((duty_cycle - (uint32_t)duty_cycle) * 100));
(uint32_t)((duty_cycle - (uint32_t)duty_cycle) * 100UL));
}
LevelDuration subghz_encoder_princeton_for_testing_yield(void* context) {

View File

@@ -151,8 +151,8 @@ void subghz_protocol_decoder_scher_khan_feed(void* context, bool level, uint32_t
break;
case ScherKhanDecoderStepSaveDuration:
if(level) {
if(duration >= (uint32_t)(subghz_protocol_scher_khan_const.te_long +
subghz_protocol_scher_khan_const.te_delta * 2)) {
if(duration >= (subghz_protocol_scher_khan_const.te_delta * 2UL +
subghz_protocol_scher_khan_const.te_long)) {
//Found stop bit
instance->decoder.parser_step = ScherKhanDecoderStepReset;
if(instance->decoder.decode_count_bit >=

View File

@@ -291,7 +291,7 @@ bool subghz_protocol_encoder_secplus_v1_deserialize(void* context, FlipperFormat
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->generic.data >> i * 8) & 0xFF;
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> (i * 8)) & 0xFF;
}
if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
FURI_LOG_E(TAG, "Unable to add Key");
@@ -550,7 +550,7 @@ bool subghz_protocol_secplus_v1_check_fixed(uint32_t fixed) {
do {
if(id1 == 0) return false;
if(!(btn == 0 || btn == 1 || btn == 2)) return false;
if(!(btn == 0 || btn == 1 || btn == 2)) return false; //-V560
} while(false);
return true;
}
@@ -588,7 +588,7 @@ void subghz_protocol_decoder_secplus_v1_get_string(void* context, FuriString* ou
if(pin <= 9999) {
furi_string_cat_printf(output, " pin:%d", pin);
} else if(10000 <= pin && pin <= 11029) {
} else if(pin <= 11029) {
furi_string_cat_printf(output, " pin:enter");
}
@@ -618,7 +618,7 @@ void subghz_protocol_decoder_secplus_v1_get_string(void* context, FuriString* ou
furi_string_cat_printf(output, " Btn:left\r\n");
} else if(instance->generic.btn == 0) {
furi_string_cat_printf(output, " Btn:middle\r\n");
} else if(instance->generic.btn == 2) {
} else if(instance->generic.btn == 2) { //-V547
furi_string_cat_printf(output, " Btn:right\r\n");
}

View File

@@ -151,7 +151,7 @@ static bool subghz_protocol_secplus_v2_mix_order_decode(uint8_t order, uint16_t
case 0x06: // 0b0110 2, 1, 0],
case 0x09: // 0b1001 2, 1, 0],
p[2] = a;
p[1] = b;
// p[1]: no change
p[0] = c;
break;
case 0x08: // 0b1000 1, 2, 0],
@@ -166,20 +166,18 @@ static bool subghz_protocol_secplus_v2_mix_order_decode(uint8_t order, uint16_t
p[1] = c;
break;
case 0x00: // 0b0000 0, 2, 1],
p[0] = a;
// p[0]: no change
p[2] = b;
p[1] = c;
break;
case 0x05: // 0b0101 1, 0, 2],
p[1] = a;
p[0] = b;
p[2] = c;
// p[2]: no change
break;
case 0x02: // 0b0010 0, 1, 2],
case 0x0A: // 0b1010 0, 1, 2],
p[0] = a;
p[1] = b;
p[2] = c;
// no reordering
break;
default:
FURI_LOG_E(TAG, "Order FAIL");
@@ -539,7 +537,7 @@ bool subghz_protocol_encoder_secplus_v2_deserialize(void* context, FlipperFormat
//update data
for(size_t i = 0; i < sizeof(uint64_t); i++) {
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> i * 8) & 0xFF;
key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> (i * 8)) & 0xFF;
}
if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) {
FURI_LOG_E(TAG, "Unable to add Key");
@@ -547,7 +545,7 @@ bool subghz_protocol_encoder_secplus_v2_deserialize(void* context, FlipperFormat
}
for(size_t i = 0; i < sizeof(uint64_t); i++) {
key_data[sizeof(uint64_t) - i - 1] = (instance->secplus_packet_1 >> i * 8) & 0xFF;
key_data[sizeof(uint64_t) - i - 1] = (instance->secplus_packet_1 >> (i * 8)) & 0xFF;
}
if(!flipper_format_update_hex(
flipper_format, "Secplus_packet_1", key_data, sizeof(uint64_t))) {
@@ -605,7 +603,7 @@ bool subghz_protocol_secplus_v2_create_data(
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->secplus_packet_1 >> i * 8) & 0xFF;
key_data[sizeof(uint64_t) - i - 1] = (instance->secplus_packet_1 >> (i * 8)) & 0xFF;
}
if(res &&
@@ -691,7 +689,7 @@ void subghz_protocol_decoder_secplus_v2_feed(void* context, bool level, uint32_t
subghz_protocol_secplus_v2_const.te_delta) {
event = ManchesterEventLongLow;
} else if(
duration >= (uint32_t)(subghz_protocol_secplus_v2_const.te_long * 2 +
duration >= (subghz_protocol_secplus_v2_const.te_long * 2UL +
subghz_protocol_secplus_v2_const.te_delta)) {
if(instance->decoder.decode_count_bit ==
subghz_protocol_secplus_v2_const.min_count_bit_for_found) {
@@ -766,7 +764,7 @@ bool subghz_protocol_decoder_secplus_v2_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->secplus_packet_1 >> i * 8) & 0xFF;
key_data[sizeof(uint64_t) - i - 1] = (instance->secplus_packet_1 >> (i * 8)) & 0xFF;
}
if(res &&

View File

@@ -372,8 +372,8 @@ void subghz_protocol_decoder_smc5326_get_string(void* context, FuriString* outpu
furi_string_cat_printf(
output,
"%s %dbit\r\n"
"Key:%07lX Te:%ldus\r\n"
"%s %ubit\r\n"
"Key:%07lX Te:%luus\r\n"
" +: " DIP_PATTERN "\r\n"
" o: " DIP_PATTERN " ",
instance->generic.protocol_name,

View File

@@ -90,7 +90,7 @@ LevelDuration subghz_file_encoder_worker_get_level_duration(void* context) {
level_duration = level_duration_make(false, -duration);
} else if(duration > 0) {
level_duration = level_duration_make(true, duration);
} else if(duration == 0) {
} else if(duration == 0) { //-V547
level_duration = level_duration_reset();
FURI_LOG_I(TAG, "Stop transmission");
instance->worker_stoping = true;

View File

@@ -189,7 +189,7 @@ bool subghz_keystore_load(SubGhzKeystore* instance, const char* file_name) {
bool result = false;
uint8_t iv[16];
uint32_t version;
SubGhzKeystoreEncryption encryption;
uint32_t encryption;
FuriString* filetype;
filetype = furi_string_alloc();
@@ -324,9 +324,9 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8
size_t total_keys = SubGhzKeyArray_size(instance->data);
result = encrypted_line_count == total_keys;
if(result) {
FURI_LOG_I(TAG, "Success. Encrypted: %d of %d", encrypted_line_count, total_keys);
FURI_LOG_I(TAG, "Success. Encrypted: %zu of %zu", encrypted_line_count, total_keys);
} else {
FURI_LOG_E(TAG, "Failure. Encrypted: %d of %d", encrypted_line_count, total_keys);
FURI_LOG_E(TAG, "Failure. Encrypted: %zu of %zu", encrypted_line_count, total_keys);
}
} while(0);
flipper_format_free(flipper_format);
@@ -349,9 +349,9 @@ bool subghz_keystore_raw_encrypted_save(
uint8_t* iv) {
bool encrypted = false;
uint32_t version;
uint32_t encryption;
FuriString* filetype;
filetype = furi_string_alloc();
SubGhzKeystoreEncryption encryption;
Storage* storage = furi_record_open(RECORD_STORAGE);
@@ -464,7 +464,7 @@ bool subghz_keystore_raw_encrypted_save(
}
stream_write_cstring(output_stream, encrypted_line);
} while(result);
} while(true);
flipper_format_free(output_flipper_format);
@@ -488,7 +488,7 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t*
bool result = false;
uint8_t iv[16];
uint32_t version;
SubGhzKeystoreEncryption encryption;
uint32_t encryption;
FuriString* str_temp;
str_temp = furi_string_alloc();

View File

@@ -532,9 +532,8 @@ uint8_t* subghz_setting_get_preset_data_by_name(SubGhzSetting* instance, const c
uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx) {
furi_assert(instance);
uint32_t* ret = FrequencyList_get(instance->frequencies, idx);
if(ret) {
return (*ret) & FREQUENCY_MASK;
if(idx < FrequencyList_size(instance->frequencies)) {
return (*FrequencyList_get(instance->frequencies, idx)) & FREQUENCY_MASK;
} else {
return 0;
}
@@ -542,9 +541,8 @@ uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx) {
uint32_t subghz_setting_get_hopper_frequency(SubGhzSetting* instance, size_t idx) {
furi_assert(instance);
uint32_t* ret = FrequencyList_get(instance->hopper_frequencies, idx);
if(ret) {
return *ret;
if(idx < FrequencyList_size(instance->frequencies)) {
return *FrequencyList_get(instance->hopper_frequencies, idx);
} else {
return 0;
}

View File

@@ -69,8 +69,11 @@ static DirWalkResult
if(dir_walk_filter(dir_walk, name, &info)) {
if(return_path != NULL) {
furi_string_printf(
return_path, "%s/%s", furi_string_get_cstr(dir_walk->path), name);
furi_string_printf( //-V576
return_path,
"%s/%s",
furi_string_get_cstr(dir_walk->path),
name);
}
if(fileinfo != NULL) {

View File

@@ -0,0 +1,8 @@
#include "float_tools.h"
#include <math.h>
#include <float.h>
bool float_is_equal(float a, float b) {
return fabsf(a - b) <= FLT_EPSILON * fmaxf(fabsf(a), fabsf(b));
}

19
lib/toolbox/float_tools.h Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
/** Compare two floating point numbers
* @param a First number to compare
* @param b Second number to compare
*
* @return bool true if a equals b, false otherwise
*/
bool float_is_equal(float a, float b);
#ifdef __cplusplus
}
#endif

View File

@@ -1,14 +1,14 @@
#include "hex.h"
bool hex_char_to_hex_nibble(char c, uint8_t* nibble) {
if((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) {
if((c >= '0' && c <= '9')) {
*nibble = c - '0';
} else if((c >= 'A' && c <= 'F')) {
*nibble = c - 'A' + 10;
} else {
*nibble = c - 'a' + 10;
}
if((c >= '0' && c <= '9')) {
*nibble = c - '0';
return true;
} else if((c >= 'A' && c <= 'F')) {
*nibble = c - 'A' + 10;
return true;
} else if(c >= 'a' && c <= 'f') {
*nibble = c - 'a' + 10;
return true;
} else {
return false;

View File

@@ -115,7 +115,7 @@ void md5_process(md5_context* ctx, const unsigned char data[64]) {
GET_UINT32_LE(X[14], data, 56);
GET_UINT32_LE(X[15], data, 60);
#define S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
#define S(x, n) (((x) << (n)) | (((x)&0xFFFFFFFF) >> (32 - (n))))
#define P(a, b, c, d, k, s, t) \
{ \
@@ -128,7 +128,7 @@ void md5_process(md5_context* ctx, const unsigned char data[64]) {
C = ctx->state[2];
D = ctx->state[3];
#define F(x, y, z) (z ^ (x & (y ^ z)))
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
P(A, B, C, D, 0, 7, 0xD76AA478);
P(D, A, B, C, 1, 12, 0xE8C7B756);
@@ -149,7 +149,7 @@ void md5_process(md5_context* ctx, const unsigned char data[64]) {
#undef F
#define F(x, y, z) (y ^ (z & (x ^ y)))
#define F(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
P(A, B, C, D, 1, 5, 0xF61E2562);
P(D, A, B, C, 6, 9, 0xC040B340);
@@ -170,7 +170,7 @@ void md5_process(md5_context* ctx, const unsigned char data[64]) {
#undef F
#define F(x, y, z) (x ^ y ^ z)
#define F(x, y, z) ((x) ^ (y) ^ (z))
P(A, B, C, D, 5, 4, 0xFFFA3942);
P(D, A, B, C, 8, 11, 0x8771F681);
@@ -191,7 +191,7 @@ void md5_process(md5_context* ctx, const unsigned char data[64]) {
#undef F
#define F(x, y, z) (y ^ (x | ~z))
#define F(x, y, z) ((y) ^ ((x) | ~(z)))
P(A, B, C, D, 0, 6, 0xF4292244);
P(D, A, B, C, 7, 10, 0x432AFF97);
@@ -295,5 +295,5 @@ void md5(const unsigned char* input, size_t ilen, unsigned char output[16]) {
md5_update(&ctx, input, ilen);
md5_finish(&ctx, output);
memset(&ctx, 0, sizeof(md5_context));
memset(&ctx, 0, sizeof(md5_context)); //-V597
}

View File

@@ -62,15 +62,15 @@ static void memcpy_output_bswap32(unsigned char* dst, const uint32_t* p) {
}
}
#define rotr32(x, n) (((x) >> n) | ((x) << (32 - n)))
#define rotr32(x, n) (((x) >> n) | ((x) << (32 - (n))))
#define ch(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
#define maj(x, y, z) (((x) & (y)) | ((z) & ((x) ^ (y))))
/* round transforms for SHA256 compression functions */
#define vf(n, i) v[(n - i) & 7]
#define vf(n, i) v[((n) - (i)) & 7]
#define hf(i) (p[i & 15] += g_1(p[(i + 14) & 15]) + p[(i + 9) & 15] + g_0(p[(i + 1) & 15]))
#define hf(i) (p[(i)&15] += g_1(p[((i) + 14) & 15]) + p[((i) + 9) & 15] + g_0(p[((i) + 1) & 15]))
#define v_cycle0(i) \
p[i] = __builtin_bswap32(p[i]); \
@@ -176,8 +176,8 @@ void sha256_finish(sha256_context* ctx, unsigned char output[32]) {
uint32_t last = (ctx->total[0] & SHA256_MASK);
ctx->wbuf[last >> 2] = __builtin_bswap32(ctx->wbuf[last >> 2]);
ctx->wbuf[last >> 2] &= 0xffffff80 << (8 * (~last & 3));
ctx->wbuf[last >> 2] |= 0x00000080 << (8 * (~last & 3));
ctx->wbuf[last >> 2] &= 0xffffff80UL << (8 * (~last & 3));
ctx->wbuf[last >> 2] |= 0x00000080UL << (8 * (~last & 3));
ctx->wbuf[last >> 2] = __builtin_bswap32(ctx->wbuf[last >> 2]);
if(last > SHA256_BLOCK_SIZE - 9) {

View File

@@ -315,8 +315,8 @@ void stream_dump_data(Stream* stream) {
size_t size = stream_size(stream);
size_t tell = stream_tell(stream);
printf("stream %p\r\n", stream);
printf("size = %u\r\n", size);
printf("tell = %u\r\n", tell);
printf("size = %zu\r\n", size);
printf("tell = %zu\r\n", tell);
printf("DATA START\r\n");
uint8_t* data = malloc(STREAM_CACHE_SIZE);
stream_rewind(stream);

View File

@@ -236,7 +236,7 @@ static int archive_extract_foreach_cb(mtar_t* tar, const mtar_header_t* header,
return 0;
}
FURI_LOG_D(TAG, "Extracting %d bytes to '%s'", header->size, header->name);
FURI_LOG_D(TAG, "Extracting %u bytes to '%s'", header->size, header->name);
FuriString* converted_fname = furi_string_alloc_set(header->name);
if(op_params->converter) {
@@ -382,4 +382,4 @@ bool tar_archive_unpack_file(
return false;
}
return archive_extract_current_file(archive, destination);
}
}

View File

@@ -15,7 +15,7 @@ size_t varint_uint32_unpack(uint32_t* value, const uint8_t* input, size_t input_
uint32_t parsed = 0;
for(i = 0; i < input_size; i++) {
parsed |= (input[i] & 0x7F) << (7 * i);
parsed |= (input[i] & 0x7FUL) << (7 * i);
if(!(input[i] & 0x80)) {
break;
@@ -73,4 +73,4 @@ size_t varint_int32_length(int32_t value) {
}
return varint_uint32_length(v);
}
}

View File

@@ -35,7 +35,7 @@ uint8_t dfu_file_validate_headers(File* dfuf, const DfuValidationParams* referen
return 0;
}
if(memcmp(dfu_prefix.szSignature, DFU_SIGNATURE, sizeof(dfu_prefix.szSignature))) {
if(memcmp(dfu_prefix.szSignature, DFU_SIGNATURE, sizeof(dfu_prefix.szSignature)) != 0) {
return 0;
}

View File

@@ -98,7 +98,7 @@ ResourceManifestEntry* resource_manifest_reader_next(ResourceManifestReader* res
furi_string_right(resource_manifest->linebuf, offs + 1);
furi_string_set(resource_manifest->entry.name, resource_manifest->linebuf);
} else if(resource_manifest->entry.type == ResourceManifestEntryTypeDirectory) {
} else if(resource_manifest->entry.type == ResourceManifestEntryTypeDirectory) { //-V547
/* Parse directory entry
D:<name> */

View File

@@ -11,7 +11,7 @@
#define UPDATE_ROOT_DIR EXT_PATH("update")
/* Need at least 4 free LFS pages before update */
#define UPDATE_MIN_INT_FREE_SPACE 2 * 4 * 1024
#define UPDATE_MIN_INT_FREE_SPACE (2 * 4 * 1024)
static const char* update_prepare_result_descr[] = {
[UpdatePrepareResultOK] = "OK",
@@ -110,7 +110,7 @@ bool update_operation_get_current_package_manifest_path(Storage* storage, FuriSt
}
static bool update_operation_persist_manifest_path(Storage* storage, const char* manifest_path) {
const uint16_t manifest_path_len = strlen(manifest_path);
const size_t manifest_path_len = strlen(manifest_path);
furi_check(manifest_path && manifest_path_len);
bool success = false;
File* file = storage_file_alloc(storage);