LCOV - code coverage report
Current view: top level - src - show_remembered_messages.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 75.0 % 28 21
Test Date: 2026-07-12 01:01:34 Functions: 100.0 % 1 1
Branches: 66.7 % 18 12

             Branch data     Line data    Source code
       1                 :             : #include "precizer.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Print delayed warning and error messages saved during the run
       5                 :             :  *
       6                 :             :  * Prints rows from the temporary `remember_history` table only when final
       7                 :             :  * remembered output is enabled. If the database is not open or no remembered
       8                 :             :  * messages exist, the function returns without output
       9                 :             :  *
      10                 :             :  * @return SUCCESS when delayed reporting is complete, otherwise FAILURE
      11                 :             :  */
      12                 :         554 : Return show_remembered_messages(void)
      13                 :             : {
      14                 :             :         // Show only when the final remembered output is enabled
      15         [ +  + ]:         554 :         if(config->show_remembered_messages_at_exit == false)
      16                 :             :         {
      17                 :             :                 // Do nothing
      18                 :         418 :                 provide(SUCCESS);
      19                 :             :         }
      20                 :             : 
      21                 :             :         // DB not initialized yet (early failure): nothing to show
      22         [ -  + ]:         136 :         if(config->db == NULL)
      23                 :             :         {
      24                 :           0 :                 provide(SUCCESS);
      25                 :             :         }
      26                 :             : 
      27                 :         136 :         sqlite3_stmt *stmt = NULL;
      28                 :         136 :         const char *select_sql =
      29                 :             :                 "SELECT message FROM temp.remember_history ORDER BY id;";
      30                 :             : 
      31                 :         136 :         int rc = sqlite3_prepare_v2(config->db,select_sql,-1,&stmt,NULL);
      32                 :             : 
      33         [ -  + ]:         136 :         if(rc != SQLITE_OK)
      34                 :             :         {
      35                 :           0 :                 log_sqlite_error(config->db,rc,NULL,
      36                 :             :                         "Failed to prepare remember_history query");
      37                 :           0 :                 provide(FAILURE);
      38                 :             :         }
      39                 :             : 
      40                 :         136 :         bool printed_header = false;
      41                 :             : 
      42         [ +  + ]:         211 :         while((rc = sqlite3_step(stmt)) == SQLITE_ROW)
      43                 :             :         {
      44         [ +  + ]:          75 :                 if(!printed_header)
      45                 :             :                 {
      46                 :             :                         // Print the header only when at least one row exists.
      47                 :          51 :                         slog(EVERY,BOLD "Warnings and errors encountered:" RESET "\n");
      48                 :          51 :                         printed_header = true;
      49                 :             :                 }
      50                 :             : 
      51                 :          75 :                 const unsigned char *text = sqlite3_column_text(stmt,0);
      52                 :          75 :                 int text_len = sqlite3_column_bytes(stmt,0);
      53                 :             : 
      54   [ +  -  +  - ]:          75 :                 if(text != NULL && text_len > 0)
      55                 :             :                 {
      56                 :             :                         // Use length-bounded output; remember_history messages are not
      57                 :             :                         // guaranteed to be null-terminated.
      58         [ +  - ]:          75 :                         if(text[text_len - 1] == '\n')
      59                 :             :                         {
      60                 :          75 :                                 slog(EVERY|UNDECOR,"%.*s",text_len,text);
      61                 :             :                         } else {
      62                 :           0 :                                 slog(EVERY|UNDECOR,"%.*s\n",text_len,text);
      63                 :             :                         }
      64                 :             :                 }
      65                 :             :         }
      66                 :             : 
      67         [ -  + ]:         136 :         if(rc != SQLITE_DONE)
      68                 :             :         {
      69                 :           0 :                 log_sqlite_error(config->db,rc,NULL,
      70                 :             :                         "Failed to read remember_history");
      71                 :           0 :                 sqlite3_finalize(stmt);
      72                 :           0 :                 provide(FAILURE);
      73                 :             :         }
      74                 :             : 
      75                 :         136 :         sqlite3_finalize(stmt);
      76                 :             : 
      77                 :         136 :         provide(SUCCESS);
      78                 :             : }
        

Generated by: LCOV version 2.0-1