LCOV - differential code coverage report
Current view: top level - src/port - quotes.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 90.9 % 11 10 1 10
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 1 1 1
Baseline: 16@8cea358b128 Branches: 75.0 % 8 6 2 6
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed (240..) days: 90.9 % 11 10 1 10
Function coverage date bins:
(240..) days: 100.0 % 1 1 1
Branch coverage date bins:
(240..) days: 75.0 % 8 6 2 6

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * quotes.c
                                  4                 :                :  *    string quoting and escaping functions
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
                                  7                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  8                 :                :  *
                                  9                 :                :  *
                                 10                 :                :  * IDENTIFICATION
                                 11                 :                :  *    src/port/quotes.c
                                 12                 :                :  *
                                 13                 :                :  *-------------------------------------------------------------------------
                                 14                 :                :  */
                                 15                 :                : 
                                 16                 :                : #include "c.h"
                                 17                 :                : 
                                 18                 :                : /*
                                 19                 :                :  * Escape (by doubling) any single quotes or backslashes in given string
                                 20                 :                :  *
                                 21                 :                :  * Note: this is used to process postgresql.conf entries and to quote
                                 22                 :                :  * string literals in pg_basebackup for writing the recovery configuration.
                                 23                 :                :  * Since postgresql.conf strings are defined to treat backslashes as escapes,
                                 24                 :                :  * we have to double backslashes here.
                                 25                 :                :  *
                                 26                 :                :  * Since this function is only used for parsing or creating configuration
                                 27                 :                :  * files, we do not care about encoding considerations.
                                 28                 :                :  *
                                 29                 :                :  * Returns a malloced() string that it's the responsibility of the caller
                                 30                 :                :  * to free.
                                 31                 :                :  */
                                 32                 :                : char *
 4117 magnus@hagander.net        33                 :CBC         556 : escape_single_quotes_ascii(const char *src)
                                 34                 :                : {
                                 35                 :            556 :     int         len = strlen(src),
                                 36                 :                :                 i,
                                 37                 :                :                 j;
                                 38                 :            556 :     char       *result = malloc(len * 2 + 1);
                                 39                 :                : 
                                 40         [ -  + ]:            556 :     if (!result)
 4117 magnus@hagander.net        41                 :UBC           0 :         return NULL;
                                 42                 :                : 
 4117 magnus@hagander.net        43         [ +  + ]:CBC       14926 :     for (i = 0, j = 0; i < len; i++)
                                 44                 :                :     {
                                 45   [ +  +  -  + ]:          14370 :         if (SQL_STR_DOUBLE(src[i], true))
                                 46                 :             44 :             result[j++] = src[i];
                                 47                 :          14370 :         result[j++] = src[i];
                                 48                 :                :     }
                                 49                 :            556 :     result[j] = '\0';
                                 50                 :            556 :     return result;
                                 51                 :                : }
        

Generated by: LCOV version 2.1-beta2-3-g6141622