[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

@@ -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);
}
}