LCOV - code coverage report
Current view: top level - libs/mem/src - mem_copy.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 60.9 % 23 14
Test Date: 2026-01-12 05:34:38 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #include "mem.h"
       2              : #include <string.h>
       3              : 
       4          206 : Return memory_copy(
       5              :         memory       *destination,
       6              :         const memory *source)
       7              : {
       8              :         /** Return status
       9              :          *  The status that will be passed to return() before exiting
      10              :          *  By default, the function worked without errors
      11              :          */
      12          206 :         Return status = SUCCESS;
      13              : 
      14          206 :         if(destination == NULL || source == NULL)
      15              :         {
      16            0 :                 slog(ERROR,"Memory management; append arguments must be non-NULL");
      17            0 :                 provide(FAILURE);
      18              :         }
      19              : 
      20          206 :         if(destination->element_size == 0)
      21              :         {
      22            0 :                 slog(ERROR,"Memory management; Destination element size is zero (uninitialized)");
      23            0 :                 provide(FAILURE);
      24              :         }
      25              : 
      26          206 :         if(source->element_size == 0)
      27              :         {
      28            0 :                 slog(ERROR,"Memory management; Source element size is zero (uninitialized)");
      29            0 :                 provide(FAILURE);
      30              :         }
      31              : 
      32          206 :         if(destination->element_size != source->element_size)
      33              :         {
      34            0 :                 slog(ERROR,"Memory management; Element size mismatch (%zu vs %zu)",
      35              :                         destination->element_size,
      36              :                         source->element_size);
      37            0 :                 provide(FAILURE);
      38              :         }
      39              : 
      40          206 :         size_t bytes_to_copy = 0;
      41              : 
      42          206 :         run(memory_guarded_size(source->element_size,source->length,&bytes_to_copy));
      43              : 
      44          206 :         if(FAILURE == status)
      45              :         {
      46            0 :                 slog(ERROR,"Memory management; Overflow computing %zu * %zu",
      47              :                         source->element_size,
      48              :                         source->length);
      49              :         }
      50              : 
      51          206 :         if(SUCCESS == status && destination->length != source->length)
      52              :         {
      53          205 :                 run(resize(destination,source->length));
      54              :         }
      55              : 
      56          206 :         if(SUCCESS == status && source->length > 0)
      57              :         {
      58          205 :                 memcpy(destination->data,source->data,bytes_to_copy);
      59              :         }
      60              : 
      61          206 :         provide(status);
      62              : }
        

Generated by: LCOV version 2.0-1