LCOV - code coverage report
Current view: top level - libs/mem/src - mem_guarded_subtract.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 81.8 % 11 9
Test Date: 2026-07-12 01:01:34 Functions: 100.0 % 1 1
Branches: 83.3 % 6 5

             Branch data     Line data    Source code
       1                 :             : #include "mem.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Subtract one size_t value from another with underflow detection
       5                 :             :  *
       6                 :             :  * Used by implementation files to detect unsigned underflow when computing
       7                 :             :  * deltas between byte counts
       8                 :             :  *
       9                 :             :  * @param left Left operand
      10                 :             :  * @param right Right operand
      11                 :             :  * @param difference Output pointer for the difference on success
      12                 :             :  * @return Return status indicating whether the subtraction succeeded
      13                 :             :  */
      14                 :           3 : Return mem_guarded_subtract(
      15                 :             :         size_t left,
      16                 :             :         size_t right,
      17                 :             :         size_t *difference)
      18                 :             : {
      19                 :             :         /* Status returned by this function through provide()
      20                 :             :            Default value assumes successful completion */
      21                 :           3 :         Return status = SUCCESS;
      22                 :             : 
      23         [ -  + ]:           3 :         if(difference == NULL)
      24                 :             :         {
      25                 :           0 :                 report("Memory management; Output pointer is NULL");
      26                 :           0 :                 provide(FAILURE);
      27                 :             :         }
      28                 :             : 
      29         [ +  + ]:           3 :         if(left < right)
      30                 :             :         {
      31                 :           2 :                 status = FAILURE;
      32                 :           2 :                 telemetry_arithmetic_guard_failures();
      33                 :             :         }
      34                 :             : 
      35         [ +  + ]:           3 :         if(TRIUMPH & status)
      36                 :             :         {
      37                 :           1 :                 *difference = left - right;
      38                 :             :         }
      39                 :             : 
      40                 :           3 :         provide(status);
      41                 :             : }
        

Generated by: LCOV version 2.0-1