Skip to content

Commit

Permalink
Remove unneeded cppcheck misra suppress
Browse files Browse the repository at this point in the history
- c2012-17.7 - memcpy, strcpy
  • Loading branch information
jciberlin authored and Igor-Misic committed Jan 19, 2025
1 parent 1dc9ece commit b903c82
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 24 deletions.
8 changes: 0 additions & 8 deletions Src/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Json_startString(char* buffer, size_t buffer_size) {
bool success = false;

if (buffer_size >= MINIMAL_SIZE) {
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case, therefore it is not used
strcpy(&buffer[0], "{");
success = true;
}
Expand All @@ -59,25 +58,19 @@ Json_addData(char* buffer, size_t buffer_size, const char* key, const char* valu
size_t total_size = strlen("\"\":\"\"") + strlen(key) + strlen(value) + 1U;

if (0 == strcmp(&buffer[index - 1U], "\"")) {
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case, therefore it is not used
strcpy(&buffer[index], ",");
++index;
}

if ((total_size + index) <= buffer_size) {
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case, therefore it is not used
strcpy(&buffer[index], "\"");
index += strlen("\"");
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case, therefore it is not used
strcpy(&buffer[index], key);
index += strlen(key);
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case, therefore it is not used
strcpy(&buffer[index], "\":\"");
index += strlen("\":\"");
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case, therefore it is not used
strcpy(&buffer[index], value);
index += strlen(value);
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case, therefore it is not used
strcpy(&buffer[index], "\"");

success = true;
Expand All @@ -92,7 +85,6 @@ Json_endString(char* buffer, size_t buffer_size) {

size_t index = strlen(buffer);
if (buffer_size >= (MINIMAL_SIZE + index)) {
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case, therefore it is not used
strcpy(&buffer[index], "}");
success = true;
}
Expand Down
4 changes: 0 additions & 4 deletions Src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,12 @@ Map_insert(Map_t* map, const byte_t* key, const byte_t* value) {
int32_t index = GetIndex(map, key, map->current_size);
if (index == INDEX_NOT_FOUND) {
if (map->current_size != map->max_map_size) {
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(&map->keys[map->current_size * map->key_size], key, (size_t)map->key_size);
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(&map->values[map->current_size * map->value_size], value, (size_t)map->value_size);
++map->current_size;
status = true;
}
} else {
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(&map->values[index * map->value_size], value, (size_t)map->value_size);
status = true;
}
Expand All @@ -95,7 +92,6 @@ Map_getValue(const Map_t* map, const byte_t* key, byte_t* value) {
if (map != NULL_PTR) {
int32_t index = GetIndex(map, key, map->current_size);
if (index != INDEX_NOT_FOUND) {
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(value, &map->values[index * map->value_size], (size_t)map->value_size);
status = true;
}
Expand Down
5 changes: 0 additions & 5 deletions Src/priority_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ PriorityQueue_enqueue(PriorityQueue_t* queue, const PriorityQueueItem_t* item) {
bool status = false;
if (!Full(queue)) {
uint8_t* buffer = queue->buffer;
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(&buffer[queue->size * queue->element_size], item->element, queue->element_size);
queue->priority_array[queue->size] = *(item->priority);
queue->size = queue->size + 1U;
Expand All @@ -109,12 +108,10 @@ PriorityQueue_enqueue(PriorityQueue_t* queue, const PriorityQueueItem_t* item) {
queue->size = queue->size - 1U;
const uint32_t current_size = queue->size;
for (uint32_t i = lowest_priority_index; i < current_size; ++i) {
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(&buffer[i * queue->element_size], &buffer[(i * queue->element_size) + queue->element_size],
queue->element_size);
queue->priority_array[i] = queue->priority_array[i + 1U];
}
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(&buffer[queue->size * queue->element_size], item->element, queue->element_size);
queue->priority_array[queue->size] = *(item->priority);
queue->size = queue->size + 1U;
Expand All @@ -130,12 +127,10 @@ PriorityQueue_dequeue(PriorityQueue_t* queue, uint8_t* element) {
status = true;
uint32_t highest_priority_index = GetHighestPriorityIndex(queue);
uint8_t* buffer = queue->buffer;
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(element, &buffer[highest_priority_index * queue->element_size], queue->element_size);
queue->size = queue->size - 1U;
const uint32_t current_size = queue->size;
for (uint32_t i = highest_priority_index; i < current_size; ++i) {
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(&buffer[i * queue->element_size], &buffer[(i * queue->element_size) + queue->element_size],
queue->element_size);
queue->priority_array[i] = queue->priority_array[i + 1U];
Expand Down
4 changes: 0 additions & 4 deletions Src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Queue_enqueue(Queue_t* queue, const uint8_t* element) {
if ((queue != NULL_PTR) && (element != NULL_PTR)) {
if (!Queue_full(queue)) {
uint8_t* buffer = queue->buffer;
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(&buffer[((queue->rear + 1U) % queue->capacity) * queue->element_size], element, queue->element_size);
queue->rear = (queue->rear + 1U) % queue->capacity;
queue->size = queue->size + 1U;
Expand All @@ -83,7 +82,6 @@ Queue_dequeue(Queue_t* queue, uint8_t* element) {
if ((queue != NULL_PTR) && (element != NULL_PTR)) {
if (!Queue_empty(queue)) {
const uint8_t* buffer = (const uint8_t*)queue->buffer;
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(element, &buffer[queue->front * queue->element_size], queue->element_size);
queue->front = (queue->front + 1U) % queue->capacity;
queue->size = queue->size - 1U;
Expand All @@ -99,7 +97,6 @@ Queue_front(const Queue_t* queue, uint8_t* element) {
if ((queue != NULL_PTR) && (element != NULL_PTR)) {
if (!Queue_empty(queue)) {
const uint8_t* buffer = (const uint8_t*)queue->buffer;
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(element, &buffer[queue->front * queue->element_size], queue->element_size);
status = true;
}
Expand All @@ -113,7 +110,6 @@ Queue_rear(const Queue_t* queue, uint8_t* element) {
if ((queue != NULL_PTR) && (element != NULL_PTR)) {
if (!Queue_empty(queue)) {
const uint8_t* buffer = (const uint8_t*)queue->buffer;
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(element, &buffer[queue->rear * queue->element_size], queue->element_size);
status = true;
}
Expand Down
3 changes: 0 additions & 3 deletions Src/sort/insertion_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,16 @@ InsertionSort_sort(byte_t* buffer, int32_t number_of_elements, int32_t element_s
byte_t* element = &max_element[0];

for (int32_t i = 1; i < number_of_elements; ++i) {
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(element, &elements[i * element_size], (size_t)element_size);

int32_t j = i - 1;
bool compare = compareFun(&elements[j * element_size], element);

while ((j >= 0) && compare) {
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(&elements[(j + 1) * element_size], &elements[j * element_size], (size_t)element_size);
--j;
compare = compareFun(&elements[j * element_size], element);
}
// cppcheck-suppress misra-c2012-17.7; return value is not needed in this case
memcpy(&elements[(j + 1) * element_size], element, (size_t)element_size);
}
}

0 comments on commit b903c82

Please sign in to comment.