Skip to content

Commit

Permalink
Fix new warnings for cppcheck 2.13.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor-Misic committed Mar 28, 2024
1 parent 53f9613 commit 113debe
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
12 changes: 6 additions & 6 deletions Tests/helper/sort_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
bool
CompareInt32(void* first, void* second) {
bool ret_val = false;
int32_t* first_element = first;
int32_t* second_element = second;
const int32_t* first_element = first;
const int32_t* second_element = second;
if (*first_element > *second_element) {
ret_val = true;
}
Expand All @@ -14,8 +14,8 @@ CompareInt32(void* first, void* second) {
bool
CompareFloat64(void* first, void* second) {
bool ret_val = false;
float64_t* first_element = first;
float64_t* second_element = second;
const float64_t* first_element = first;
const float64_t* second_element = second;
if (*first_element > *second_element) {
ret_val = true;
}
Expand All @@ -25,8 +25,8 @@ CompareFloat64(void* first, void* second) {
bool
CompareUint64(void* first, void* second) {
bool ret_val = false;
uint64_t* first_element = first;
uint64_t* second_element = second;
const uint64_t* first_element = first;
const uint64_t* second_element = second;
if (*first_element > *second_element) {
ret_val = true;
}
Expand Down
14 changes: 7 additions & 7 deletions Tests/test_base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ TEST(Base64, Base64_decode) {
{
// Success
char text[] = "IMProject is a very cool project!";
char base64[] = "SU1Qcm9qZWN0IGlzIGEgdmVyeSBjb29sIHByb2plY3Qh";
const char base64[] = "SU1Qcm9qZWN0IGlzIGEgdmVyeSBjb29sIHByb2plY3Qh";
uint8_t string[200];
int32_t success = Base64_decode(base64, strlen(base64), string, sizeof(string));
TEST_ASSERT_EQUAL_MEMORY(text, string, strlen(text));
TEST_ASSERT_EQUAL_INT32(0, success);
}
{
// Output size is too big
char base64[] = "SU1Qcm9qZWN0IGlzIGEgdmVyeSBjb29sIHByb2plY3Qh";
const char base64[] = "SU1Qcm9qZWN0IGlzIGEgdmVyeSBjb29sIHByb2plY3Qh";
uint8_t string[10];
int32_t success = Base64_decode(base64, strlen(base64), string, sizeof(string));
TEST_ASSERT_EQUAL_INT32(1, success);
}
{
// Success
char text[] = "B?E(H+MbQeThWmZq4t7w!z%C*F)J@NcR";
char base64[] = "Qj9FKEgrTWJRZVRoV21acTR0N3cheiVDKkYpSkBOY1I=";
const char base64[] = "Qj9FKEgrTWJRZVRoV21acTR0N3cheiVDKkYpSkBOY1I=";
uint8_t string[200];
int32_t success = Base64_decode(base64, strlen(base64), string, sizeof(string));
TEST_ASSERT_EQUAL_MEMORY(text, string, strlen(text));
Expand All @@ -93,7 +93,7 @@ TEST(Base64, Base64_decode) {
{
// Success
char text[] = "Hehe";
char base64[] = "SGVoZQ==";
const char base64[] = "SGVoZQ==";
uint8_t string[200];
int32_t success = Base64_decode(base64, strlen(base64), string, sizeof(string));
TEST_ASSERT_EQUAL_MEMORY(text, string, strlen(text));
Expand All @@ -102,22 +102,22 @@ TEST(Base64, Base64_decode) {
{
// Success
char text[] = "Hehe";
char base64[] = "SGVoZQ1==";
const char base64[] = "SGVoZQ1==";
uint8_t string[200];
int32_t success = Base64_decode(base64, strlen(base64), string, sizeof(string));
TEST_ASSERT_EQUAL_MEMORY(text, string, strlen(text));
TEST_ASSERT_EQUAL_INT32(0, success);
}
{
// Output size is too big
char base64[] = "Qj9FKEgrTWJRZVRoV21acTR0N3cheiVDKkYpSkBOY1I=";
const char base64[] = "Qj9FKEgrTWJRZVRoV21acTR0N3cheiVDKkYpSkBOY1I=";
uint8_t string[31];
int32_t success = Base64_decode(base64, strlen(base64), string, sizeof(string));
TEST_ASSERT_EQUAL_INT32(1, success);
}
{
// Fail, length = 0
char base64[] = "SGVoZQ==";
const char base64[] = "SGVoZQ==";
uint8_t string[200];
int32_t success = Base64_decode(base64, 0U, string, sizeof(string));
TEST_ASSERT_EQUAL_INT32(1, success);
Expand Down
18 changes: 9 additions & 9 deletions Tests/test_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ TEST(Json, Json_endString) {

TEST(Json, Json_findByKey) {
{
char json_string[] =
const char json_string[] =
"{\"public_key\":\"u1zeY+TBbtYlDIzZsLH16RJ9aIBmxTINpLXSkTpaikQ=\",\"public_key_signature\":\"sQjximnEuRAsf+mAuTURcXASUS5vkl5xU0SNvvAcX+Mfc7es+xXw/Lgo0bfMNY+ShKe5VjbIg3DaSxJvLbhX+w==\"}";
char value[200];
size_t size = 200;

char key_1[] = "public_key";
const char key_1[] = "public_key";
TEST_ASSERT_TRUE(Json_findByKey(json_string, strlen(json_string), key_1, value, size));
TEST_ASSERT_EQUAL_STRING("u1zeY+TBbtYlDIzZsLH16RJ9aIBmxTINpLXSkTpaikQ=", value);

char key_2[] = "public_key_signature";
const char key_2[] = "public_key_signature";
TEST_ASSERT_TRUE(Json_findByKey(json_string, strlen(json_string), key_2, value, size));
TEST_ASSERT_EQUAL_STRING("sQjximnEuRAsf+mAuTURcXASUS5vkl5xU0SNvvAcX+Mfc7es+xXw/Lgo0bfMNY+ShKe5VjbIg3DaSxJvLbhX+w==",
value);

char key_3[] = "public";
const char key_3[] = "public";
TEST_ASSERT_FALSE(Json_findByKey(json_string, strlen(json_string), key_3, value, size));

char key_4[] = "\"public_key\"";
const char key_4[] = "\"public_key\"";
TEST_ASSERT_FALSE(Json_findByKey(json_string, strlen(json_string), key_4, value, size));

size = 45; // 44 + '/0' needed for full string
Expand All @@ -82,18 +82,18 @@ TEST(Json, Json_findByKey) {
TEST_ASSERT_FALSE(Json_findByKey(json_string, strlen(json_string), key_same_size_as_buffer, value, size));

size = 200;
char key_non_existing[] = "non_existing_key";
const char key_non_existing[] = "non_existing_key";
TEST_ASSERT_FALSE(Json_findByKey(json_string, strlen(json_string), key_non_existing, value, size));

//missing quotation marks for value
char broken_json_string_1[] = "{\"public_key\": blabla }";
const char broken_json_string_1[] = "{\"public_key\": blabla }";
TEST_ASSERT_FALSE(Json_findByKey(broken_json_string_1, strlen(broken_json_string_1), key_1, value, size));

//missing quotation mark at the end for value
char broken_json_string_2[] = "{\"public_key\": \"blabla }";
const char broken_json_string_2[] = "{\"public_key\": \"blabla }";
TEST_ASSERT_FALSE(Json_findByKey(broken_json_string_2, strlen(broken_json_string_2), key_1, value, size));

char json_string_with_space[] = "{ \"public_key\" : \"u1zeY+TBbtYlDIzZsLH16RJ9aIBmxTINpLXSkTpaikQ=\" }";
const char json_string_with_space[] = "{ \"public_key\" : \"u1zeY+TBbtYlDIzZsLH16RJ9aIBmxTINpLXSkTpaikQ=\" }";
TEST_ASSERT_TRUE(Json_findByKey(json_string_with_space, strlen(json_string_with_space), key_1, value, size));
TEST_ASSERT_EQUAL_STRING("u1zeY+TBbtYlDIzZsLH16RJ9aIBmxTINpLXSkTpaikQ=", value);
}
Expand Down
28 changes: 14 additions & 14 deletions Tests/test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,48 +66,48 @@ TEST(Utils, Utils_StringToUint32) {
TEST_ASSERT_TRUE(Utils_StringToUint32("2165217", 7U, &ui32_number));
TEST_ASSERT_EQUAL_UINT32(ui32_number, 2165217U);

char number_string[] = "1234567890";
const char number_string[] = "1234567890";
TEST_ASSERT_TRUE(Utils_StringToUint32(number_string, strlen(number_string), &ui32_number));
TEST_ASSERT_EQUAL_UINT32(ui32_number, 1234567890U);

char max_uint32_number_string[] = "4294967295";
const char max_uint32_number_string[] = "4294967295";
TEST_ASSERT_TRUE(Utils_StringToUint32(max_uint32_number_string, strlen(max_uint32_number_string), &ui32_number));
TEST_ASSERT_EQUAL_UINT32(ui32_number, 4294967295U);

char overflow_1_uint32_number_string[] = "4294967296";
const char overflow_1_uint32_number_string[] = "4294967296";
TEST_ASSERT_FALSE(Utils_StringToUint32(overflow_1_uint32_number_string, strlen(overflow_1_uint32_number_string),
&ui32_number));

char overflow_2_uint32_number_string[] = "5294967295";
const char overflow_2_uint32_number_string[] = "5294967295";
TEST_ASSERT_FALSE(Utils_StringToUint32(overflow_2_uint32_number_string, strlen(overflow_2_uint32_number_string),
&ui32_number));

char not_a_number_string[] = "A";
const char not_a_number_string[] = "A";
TEST_ASSERT_FALSE(Utils_StringToUint32(not_a_number_string, strlen(not_a_number_string), &ui32_number));

char not_a_number_2_string[] = "1A1";
const char not_a_number_2_string[] = "1A1";
TEST_ASSERT_FALSE(Utils_StringToUint32(not_a_number_2_string, strlen(not_a_number_2_string), &ui32_number));

char not_a_number_3_string[] = "123456789A";
const char not_a_number_3_string[] = "123456789A";
TEST_ASSERT_FALSE(Utils_StringToUint32(not_a_number_3_string, strlen(not_a_number_3_string), &ui32_number));

char not_a_number_4_string[] = "429496729A";
const char not_a_number_4_string[] = "429496729A";
TEST_ASSERT_FALSE(Utils_StringToUint32(not_a_number_4_string, strlen(not_a_number_4_string), &ui32_number));

char number_string_edge_case_1[] = "/";
const char number_string_edge_case_1[] = "/";
TEST_ASSERT_FALSE(Utils_StringToUint32(number_string_edge_case_1, strlen(number_string_edge_case_1), &ui32_number));

char number_string_edge_case_2[] = ":";
const char number_string_edge_case_2[] = ":";
TEST_ASSERT_FALSE(Utils_StringToUint32(number_string_edge_case_2, strlen(number_string_edge_case_2), &ui32_number));

const uint8_t force_overflow_check_size = 10U;
char number_string_edge_case_3[10U] = "12345A";
uint8_t force_overflow_check_size = 10U;
const char number_string_edge_case_3[10U] = "12345A";
TEST_ASSERT_FALSE(Utils_StringToUint32(number_string_edge_case_3, force_overflow_check_size, &ui32_number));

char number_string_edge_case_4[] = "123456789/";
const char number_string_edge_case_4[] = "123456789/";
TEST_ASSERT_FALSE(Utils_StringToUint32(number_string_edge_case_4, strlen(number_string_edge_case_4), &ui32_number));

char number_string_edge_case_5[] = "123456789:";
const char number_string_edge_case_5[] = "123456789:";
TEST_ASSERT_FALSE(Utils_StringToUint32(number_string_edge_case_5, strlen(number_string_edge_case_5), &ui32_number));
}

Expand Down

0 comments on commit 113debe

Please sign in to comment.