LCOV - code coverage report
Current view: top level - libs/mem/src - mem_getstring.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 54.3 % 35 19
Test Date: 2026-03-01 04:31:48 Functions: 100.0 % 2 2
Branches: 45.8 % 24 11

             Branch data     Line data    Source code
       1                 :             : #include "mem.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Shared zero-terminated buffer used when descriptors are unavailable.
       5                 :             :  */
       6                 :             : static char empty_string[] = "";
       7                 :             : 
       8                 :        5947 : const char *memory_getcstring(const memory *memory_object)
       9                 :             : {
      10         [ -  + ]:        5947 :         if(memory_object == NULL)
      11                 :             :         {
      12                 :           0 :                 return empty_string;
      13                 :             :         }
      14                 :             : 
      15                 :        5947 :         const char *text = (const char *)memory_const_data_checked(memory_object,sizeof(char));
      16                 :             : 
      17         [ +  + ]:        5947 :         if(text == NULL)
      18                 :             :         {
      19                 :         516 :                 return(empty_string);
      20                 :             :         }
      21                 :             : 
      22         [ -  + ]:        5431 :         if(memory_object->length == 0)
      23                 :             :         {
      24                 :           0 :                 return(empty_string);
      25                 :             :         }
      26                 :             : 
      27                 :        5431 :         size_t visible_length = 0;
      28                 :             : 
      29         [ -  + ]:        5431 :         if(CRITICAL & memory_string_length(memory_object,&visible_length))
      30                 :             :         {
      31                 :           0 :                 return(empty_string);
      32                 :             :         }
      33                 :             : 
      34         [ -  + ]:        5431 :         if(visible_length >= memory_object->length)
      35                 :             :         {
      36                 :           0 :                 return(empty_string);
      37                 :             :         }
      38                 :             : 
      39                 :        5431 :         return(text);
      40                 :             : }
      41                 :             : 
      42                 :         322 : char *memory_getstring(memory *memory_object)
      43                 :             : {
      44         [ -  + ]:         322 :         if(memory_object == NULL)
      45                 :             :         {
      46                 :           0 :                 return(empty_string);
      47                 :             :         }
      48                 :             : 
      49                 :         322 :         char *text = (char *)memory_data_checked(memory_object,sizeof(char));
      50                 :             : 
      51         [ -  + ]:         322 :         if(text == NULL)
      52                 :             :         {
      53                 :           0 :                 return(empty_string);
      54                 :             :         }
      55                 :             : 
      56         [ -  + ]:         322 :         if(memory_object->length == 0)
      57                 :             :         {
      58         [ #  # ]:           0 :                 if(CRITICAL & memory_resize(memory_object,1,UCHAR_MAX))
      59                 :             :                 {
      60                 :           0 :                         return(empty_string);
      61                 :             :                 }
      62                 :             : 
      63                 :           0 :                 text = (char *)memory_data_checked(memory_object,sizeof(char));
      64                 :             : 
      65         [ #  # ]:           0 :                 if(text == NULL)
      66                 :             :                 {
      67                 :           0 :                         return(empty_string);
      68                 :             :                 }
      69                 :             : 
      70                 :           0 :                 text[0] = '\0';
      71                 :           0 :                 return(text);
      72                 :             :         }
      73                 :             : 
      74                 :         322 :         size_t visible_length = 0;
      75                 :             : 
      76         [ -  + ]:         322 :         if(CRITICAL & memory_string_length(memory_object,&visible_length))
      77                 :             :         {
      78                 :           0 :                 return(empty_string);
      79                 :             :         }
      80                 :             : 
      81         [ -  + ]:         322 :         if(visible_length >= memory_object->length)
      82                 :             :         {
      83                 :           0 :                 text[0] = '\0';
      84                 :           0 :                 return(text);
      85                 :             :         }
      86                 :             : 
      87                 :         322 :         return(text);
      88                 :             : }
        

Generated by: LCOV version 2.0-1