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-03-01 04:31:48 Functions: 100.0 % 1 1
Branches: 57.1 % 28 16

             Branch data     Line data    Source code
       1                 :             : #include "mem.h"
       2                 :             : #include <string.h>
       3                 :             : 
       4                 :         407 : Return memory_copy(
       5                 :             :         memory       *destination,
       6                 :             :         const memory *source)
       7                 :             : {
       8                 :             :         /* Status returned by this function through provide()
       9                 :             :            Default value assumes successful completion */
      10                 :         407 :         Return status = SUCCESS;
      11                 :             : 
      12   [ +  -  -  + ]:         407 :         if(destination == NULL || source == NULL)
      13                 :             :         {
      14                 :           0 :                 report("Memory management; append arguments must be non-NULL");
      15                 :           0 :                 provide(FAILURE);
      16                 :             :         }
      17                 :             : 
      18         [ -  + ]:         407 :         if(destination->element_size == 0)
      19                 :             :         {
      20                 :           0 :                 report("Memory management; Destination element size is zero (uninitialized)");
      21                 :           0 :                 provide(FAILURE);
      22                 :             :         }
      23                 :             : 
      24         [ -  + ]:         407 :         if(source->element_size == 0)
      25                 :             :         {
      26                 :           0 :                 report("Memory management; Source element size is zero (uninitialized)");
      27                 :           0 :                 provide(FAILURE);
      28                 :             :         }
      29                 :             : 
      30         [ -  + ]:         407 :         if(destination->element_size != source->element_size)
      31                 :             :         {
      32                 :           0 :                 report("Memory management; Element size mismatch (%zu vs %zu)",
      33                 :             :                         destination->element_size,
      34                 :             :                         source->element_size);
      35                 :           0 :                 provide(FAILURE);
      36                 :             :         }
      37                 :             : 
      38                 :         407 :         size_t bytes_to_copy = 0;
      39                 :             : 
      40   [ +  -  -  + ]:         407 :         run(memory_guarded_size(source->element_size,source->length,&bytes_to_copy));
      41                 :             : 
      42         [ -  + ]:         407 :         if(CRITICAL & status)
      43                 :             :         {
      44                 :           0 :                 report("Memory management; Overflow computing %zu * %zu",
      45                 :             :                         source->element_size,
      46                 :             :                         source->length);
      47                 :             :         }
      48                 :             : 
      49   [ +  -  +  + ]:         407 :         if((TRIUMPH & status) && destination->length != source->length)
      50                 :             :         {
      51   [ +  -  -  + ]:         406 :                 run(resize(destination,source->length));
      52                 :             :         }
      53                 :             : 
      54   [ +  -  +  + ]:         407 :         if((TRIUMPH & status) && source->length > 0)
      55                 :             :         {
      56                 :         406 :                 memcpy(destination->data,source->data,bytes_to_copy);
      57                 :             :         }
      58                 :             : 
      59                 :         407 :         provide(status);
      60                 :             : }
        

Generated by: LCOV version 2.0-1