LCOV - code coverage report
Current view: top level - src - blocks_to_bytes.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 83.3 % 6 5
Test Date: 2026-03-31 13:51:38 Functions: 100.0 % 1 1
Branches: 75.0 % 4 3

             Branch data     Line data    Source code
       1                 :             : #include "precizer.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Convert POSIX `st_blocks` units into bytes.
       5                 :             :  *
       6                 :             :  * @details POSIX defines `st_blocks` in 512-byte units regardless of the
       7                 :             :  * filesystem I/O block size. Some filesystems may report non-positive values
       8                 :             :  * for special files; those are normalized to zero.
       9                 :             :  *
      10                 :             :  * @param blocks Allocated block count from file metadata.
      11                 :             :  * @return Allocated bytes as `blocks * POSIX_STAT_BLOCK_BYTES`, or zero when
      12                 :             :  *         @p blocks is less than or equal to zero, or SIZE_MAX when the result
      13                 :             :  *         would overflow `size_t`.
      14                 :             :  */
      15                 :        4200 : size_t blocks_to_bytes(const blkcnt_t blocks)
      16                 :             : {
      17         [ +  + ]:        4200 :         if(blocks <= 0)
      18                 :             :         {
      19                 :          22 :                 return 0;
      20                 :             :         }
      21                 :             : 
      22                 :             :         // Guard against multiplication overflow: if blocks exceeds the safe range,
      23                 :             :         // return SIZE_MAX as a saturating upper bound instead of wrapping around
      24         [ -  + ]:        4178 :         if((size_t)blocks > SIZE_MAX / POSIX_STAT_BLOCK_BYTES)
      25                 :             :         {
      26                 :           0 :                 return SIZE_MAX;
      27                 :             :         }
      28                 :             : 
      29                 :        4178 :         return (size_t)blocks * POSIX_STAT_BLOCK_BYTES;
      30                 :             : }
        

Generated by: LCOV version 2.0-1