LCOV - differential code coverage report
Current view: top level - src/fe_utils - mbprint.c (source / functions) Coverage Total Hit LBC UBC GNC CBC
Current: ba12a202ce1b5581dc0ed149cf3f637d7897ad5d vs 2866d8c7dbfc9d882a7d80fef93fbbe763709932 Lines: 74.2 % 186 138 48 10 128
Current Date: 2026-08-27 14:31:44 +0300 Functions: 80.0 % 10 8 2 2 6
Baseline: lcov-20260827-baseline Branches: 61.3 % 142 87 2 53 6 81
Baseline Date: 2026-08-27 14:31:58 +0300 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(7,30] days: 100.0 % 10 10 10
(30,360] days: 0.0 % 4 0 4
(360..) days: 74.4 % 172 128 44 128
Function coverage date bins:
(7,30] days: 100.0 % 2 2 2
(360..) days: 75.0 % 8 6 2 6
Branch coverage date bins:
(7,30] days: 100.0 % 6 6 6
(360..) days: 59.6 % 136 81 2 53 81

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * Multibyte character printing support for frontend code
                                  4                 :                :  *
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
                                  7                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  8                 :                :  *
                                  9                 :                :  * src/fe_utils/mbprint.c
                                 10                 :                :  *
                                 11                 :                :  *-------------------------------------------------------------------------
                                 12                 :                :  */
                                 13                 :                : #include "postgres_fe.h"
                                 14                 :                : 
                                 15                 :                : #include "fe_utils/mbprint.h"
                                 16                 :                : 
                                 17                 :                : #include "libpq-fe.h"
                                 18                 :                : 
                                 19                 :                : 
                                 20                 :                : /*
                                 21                 :                :  * To avoid version-skew problems, this file must not use declarations
                                 22                 :                :  * from pg_wchar.h: the encoding IDs we are dealing with are determined
                                 23                 :                :  * by the libpq.so we are linked with, and that might not match the
                                 24                 :                :  * numbers we see at compile time.  (If this file were inside libpq,
                                 25                 :                :  * the problem would go away...)
                                 26                 :                :  *
                                 27                 :                :  * Hence, we have our own definition of pg_wchar, and we get the values
                                 28                 :                :  * of any needed encoding IDs on-the-fly.
                                 29                 :                :  */
                                 30                 :                : 
                                 31                 :                : typedef unsigned int pg_wchar;
                                 32                 :                : 
                                 33                 :                : static int
 6162 tgl@sss.pgh.pa.us          34                 :CBC     2760938 : pg_get_utf8_id(void)
                                 35                 :                : {
                                 36                 :                :     static int  utf8_id = -1;
                                 37                 :                : 
 6893                            38         [ +  + ]:        2760938 :     if (utf8_id < 0)
                                 39                 :           7384 :         utf8_id = pg_char_to_encoding("utf8");
                                 40                 :        2760938 :     return utf8_id;
                                 41                 :                : }
                                 42                 :                : 
                                 43                 :                : #define PG_UTF8     pg_get_utf8_id()
                                 44                 :                : 
                                 45                 :                : 
                                 46                 :                : /*
                                 47                 :                :  * Convert a UTF-8 character to a Unicode code point.
                                 48                 :                :  * This is a one-character version of pg_utf2wchar_with_len.
                                 49                 :                :  *
                                 50                 :                :  * No error checks here, c must point to a long-enough string.
                                 51                 :                :  */
                                 52                 :                : static char32_t
 5853 tgl@sss.pgh.pa.us          53                 :UBC           0 : utf8_to_unicode(const unsigned char *c)
                                 54                 :                : {
 9072 bruce@momjian.us           55         [ #  # ]:              0 :     if ((*c & 0x80) == 0)
  302 jdavis@postgresql.or       56                 :              0 :         return (char32_t) c[0];
 9072 bruce@momjian.us           57         [ #  # ]:              0 :     else if ((*c & 0xe0) == 0xc0)
  302 jdavis@postgresql.or       58                 :              0 :         return (char32_t) (((c[0] & 0x1f) << 6) |
 9072 bruce@momjian.us           59                 :              0 :                            (c[1] & 0x3f));
                                 60         [ #  # ]:              0 :     else if ((*c & 0xf0) == 0xe0)
  302 jdavis@postgresql.or       61                 :              0 :         return (char32_t) (((c[0] & 0x0f) << 12) |
 9072 bruce@momjian.us           62                 :              0 :                            ((c[1] & 0x3f) << 6) |
                                 63                 :              0 :                            (c[2] & 0x3f));
 5855 tgl@sss.pgh.pa.us          64         [ #  # ]:              0 :     else if ((*c & 0xf8) == 0xf0)
  302 jdavis@postgresql.or       65                 :              0 :         return (char32_t) (((c[0] & 0x07) << 18) |
 9072 bruce@momjian.us           66                 :              0 :                            ((c[1] & 0x3f) << 12) |
                                 67                 :              0 :                            ((c[2] & 0x3f) << 6) |
                                 68                 :              0 :                            (c[3] & 0x3f));
                                 69                 :                :     else
                                 70                 :                :         /* that is an invalid code on purpose */
 9082 ishii@postgresql.org       71                 :              0 :         return 0xffffffff;
                                 72                 :                : }
                                 73                 :                : 
                                 74                 :                : 
                                 75                 :                : /*
                                 76                 :                :  * Unicode 3.1 compliant validation : for each category, it checks the
                                 77                 :                :  * combination of each byte to make sure it maps to a valid range. It also
                                 78                 :                :  * returns -1 for the following UCS values: ucs > 0x10ffff ucs & 0xfffe =
                                 79                 :                :  * 0xfffe 0xfdd0 < ucs < 0xfdef ucs & 0xdb00 = 0xd800 (surrogates)
                                 80                 :                :  */
                                 81                 :                : static int
 9082 ishii@postgresql.org       82                 :CBC    14078163 : utf_charcheck(const unsigned char *c)
                                 83                 :                : {
 9072 bruce@momjian.us           84         [ +  + ]:       14078163 :     if ((*c & 0x80) == 0)
 9082 ishii@postgresql.org       85                 :       14076441 :         return 1;
 9072 bruce@momjian.us           86         [ +  + ]:           1722 :     else if ((*c & 0xe0) == 0xc0)
                                 87                 :                :     {
                                 88                 :                :         /* two-byte char */
                                 89   [ +  +  +  - ]:           1495 :         if (((c[1] & 0xc0) == 0x80) && ((c[0] & 0x1f) > 0x01))
 9082 ishii@postgresql.org       90                 :           1463 :             return 2;
                                 91                 :             32 :         return -1;
                                 92                 :                :     }
 9072 bruce@momjian.us           93         [ +  + ]:            227 :     else if ((*c & 0xf0) == 0xe0)
                                 94                 :                :     {
                                 95                 :                :         /* three-byte char */
 9082 ishii@postgresql.org       96         [ +  - ]:            207 :         if (((c[1] & 0xc0) == 0x80) &&
                                 97   [ -  +  -  - ]:            207 :             (((c[0] & 0x0f) != 0x00) || ((c[1] & 0x20) == 0x20)) &&
 9072 bruce@momjian.us           98         [ +  - ]:            207 :             ((c[2] & 0xc0) == 0x80))
                                 99                 :                :         {
                                100                 :            207 :             int         z = c[0] & 0x0f;
                                101                 :            207 :             int         yx = ((c[1] & 0x3f) << 6) | (c[0] & 0x3f);
                                102                 :            207 :             int         lx = yx & 0x7f;
                                103                 :                : 
                                104                 :                :             /* check 0xfffe/0xffff, 0xfdd0..0xfedf range, surrogates */
 9082 ishii@postgresql.org      105         [ +  + ]:            207 :             if (((z == 0x0f) &&
                                106         [ +  - ]:             32 :                  (((yx & 0xffe) == 0xffe) ||
 3354 tgl@sss.pgh.pa.us         107   [ -  +  -  -  :            207 :                   (((yx & 0xf80) == 0xd80) && (lx >= 0x30) && (lx <= 0x4f)))) ||
                                        -  -  -  + ]
 9072 bruce@momjian.us          108         [ #  # ]:UBC           0 :                 ((z == 0x0d) && ((yx & 0xb00) == 0x800)))
 9082 ishii@postgresql.org      109                 :              0 :                 return -1;
 9082 ishii@postgresql.org      110                 :CBC         207 :             return 3;
                                111                 :                :         }
 9082 ishii@postgresql.org      112                 :UBC           0 :         return -1;
                                113                 :                :     }
 9072 bruce@momjian.us          114         [ +  - ]:CBC          20 :     else if ((*c & 0xf8) == 0xf0)
                                115                 :                :     {
                                116                 :             20 :         int         u = ((c[0] & 0x07) << 2) | ((c[1] & 0x30) >> 4);
                                117                 :                : 
                                118                 :                :         /* four-byte char */
 9082 ishii@postgresql.org      119   [ +  -  +  - ]:             20 :         if (((c[1] & 0xc0) == 0x80) &&
                                120         [ +  - ]:             20 :             (u > 0x00) && (u <= 0x10) &&
 9072 bruce@momjian.us          121   [ +  -  +  - ]:             20 :             ((c[2] & 0xc0) == 0x80) && ((c[3] & 0xc0) == 0x80))
                                122                 :                :         {
                                123                 :                :             /* test for 0xzzzzfffe/0xzzzzfffff */
 9082 ishii@postgresql.org      124   [ +  -  -  + ]:             20 :             if (((c[1] & 0x0f) == 0x0f) && ((c[2] & 0x3f) == 0x3f) &&
 9072 bruce@momjian.us          125         [ #  # ]:UBC           0 :                 ((c[3] & 0x3e) == 0x3e))
 9082 ishii@postgresql.org      126                 :              0 :                 return -1;
 9082 ishii@postgresql.org      127                 :CBC          20 :             return 4;
                                128                 :                :         }
 9082 ishii@postgresql.org      129                 :UBC           0 :         return -1;
                                130                 :                :     }
                                131                 :              0 :     return -1;
                                132                 :                : }
                                133                 :                : 
                                134                 :                : 
                                135                 :                : static void
 9082 ishii@postgresql.org      136                 :CBC          16 : mb_utf_validate(unsigned char *pwcs)
                                137                 :                : {
                                138                 :             16 :     unsigned char *p = pwcs;
                                139                 :                : 
 9072 bruce@momjian.us          140         [ +  + ]:             72 :     while (*pwcs)
                                141                 :                :     {
                                142                 :                :         int         len;
                                143                 :                : 
 7503                           144         [ +  + ]:             56 :         if ((len = utf_charcheck(pwcs)) > 0)
                                145                 :                :         {
 9072                           146         [ -  + ]:             40 :             if (p != pwcs)
                                147                 :                :             {
                                148                 :                :                 int         i;
                                149                 :                : 
 7503 bruce@momjian.us          150         [ #  # ]:UBC           0 :                 for (i = 0; i < len; i++)
 9082 ishii@postgresql.org      151                 :              0 :                     *p++ = *pwcs++;
                                152                 :                :             }
                                153                 :                :             else
                                154                 :                :             {
 7503 bruce@momjian.us          155                 :CBC          40 :                 pwcs += len;
                                156                 :             40 :                 p += len;
                                157                 :                :             }
                                158                 :                :         }
                                159                 :                :         else
                                160                 :                :             /* we skip the char */
 9082 ishii@postgresql.org      161                 :             16 :             pwcs++;
                                162                 :                :     }
 9072 bruce@momjian.us          163         [ +  - ]:             16 :     if (p != pwcs)
 9082 ishii@postgresql.org      164                 :             16 :         *p = '\0';
                                165                 :             16 : }
                                166                 :                : 
                                167                 :                : 
                                168                 :                : static bool
   16 peter@eisentraut.org      169                 :GNC     2759230 : mb_utf_is_valid(const unsigned char *pwcs)
                                170                 :                : {
                                171         [ +  + ]:       16837321 :     while (*pwcs)
                                172                 :                :     {
                                173                 :                :         int         len;
                                174                 :                : 
                                175         [ +  + ]:       14078107 :         if ((len = utf_charcheck(pwcs)) > 0)
                                176                 :       14078091 :             pwcs += len;
                                177                 :                :         else
                                178                 :             16 :             return false;
                                179                 :                : 
                                180                 :                :     }
                                181                 :        2759214 :     return true;
                                182                 :                : }
                                183                 :                : 
                                184                 :                : 
                                185                 :                : /*
                                186                 :                :  * public functions : wcswidth and mbvalidate
                                187                 :                :  */
                                188                 :                : 
                                189                 :                : /*
                                190                 :                :  * pg_wcswidth is the dumb display-width function.
                                191                 :                :  * It assumes that everything will appear on one line.
                                192                 :                :  * OTOH it is easier to use than pg_wcssize if this applies to you.
                                193                 :                :  */
                                194                 :                : int
 5286 tgl@sss.pgh.pa.us         195                 :UBC           0 : pg_wcswidth(const char *pwcs, size_t len, int encoding)
                                196                 :                : {
 7267 bruce@momjian.us          197                 :              0 :     int         width = 0;
                                198                 :                : 
 7503                           199         [ #  # ]:              0 :     while (len > 0)
                                200                 :                :     {
                                201                 :                :         int         chlen,
                                202                 :                :                     chwidth;
                                203                 :                : 
 5286 tgl@sss.pgh.pa.us         204                 :              0 :         chlen = PQmblen(pwcs, encoding);
                                205         [ #  # ]:              0 :         if (len < (size_t) chlen)
 7267 bruce@momjian.us          206                 :              0 :             break;              /* Invalid string */
                                207                 :                : 
 5286 tgl@sss.pgh.pa.us         208                 :              0 :         chwidth = PQdsplen(pwcs, encoding);
 7503 bruce@momjian.us          209         [ #  # ]:              0 :         if (chwidth > 0)
                                210                 :              0 :             width += chwidth;
                                211                 :                : 
                                212                 :              0 :         pwcs += chlen;
 5286 tgl@sss.pgh.pa.us         213                 :              0 :         len -= chlen;
                                214                 :                :     }
 7503 bruce@momjian.us          215                 :              0 :     return width;
                                216                 :                : }
                                217                 :                : 
                                218                 :                : /*
                                219                 :                :  * pg_wcssize takes the given string in the given encoding and returns three
                                220                 :                :  * values:
                                221                 :                :  *    result_width: Width in display characters of the longest line in string
                                222                 :                :  *    result_height: Number of lines in display output
                                223                 :                :  *    result_format_size: Number of bytes required to store formatted
                                224                 :                :  *      representation of string
                                225                 :                :  *
                                226                 :                :  * This MUST be kept in sync with pg_wcsformat!
                                227                 :                :  */
                                228                 :                : void
 5464 peter_e@gmx.net           229                 :CBC      946411 : pg_wcssize(const unsigned char *pwcs, size_t len, int encoding,
                                230                 :                :            int *result_width, int *result_height, int *result_format_size)
                                231                 :                : {
                                232                 :                :     int         w,
 7267 bruce@momjian.us          233                 :         946411 :                 chlen = 0,
                                234                 :         946411 :                 linewidth = 0;
                                235                 :         946411 :     int         width = 0;
                                236                 :         946411 :     int         height = 1;
                                237                 :         946411 :     int         format_size = 0;
                                238                 :                : 
 7503                           239   [ +  +  +  - ]:       11326037 :     for (; *pwcs && len > 0; pwcs += chlen)
                                240                 :                :     {
 5294 peter_e@gmx.net           241                 :       10379626 :         chlen = PQmblen((const char *) pwcs, encoding);
 7267 bruce@momjian.us          242         [ -  + ]:       10379626 :         if (len < (size_t) chlen)
 7503 bruce@momjian.us          243                 :UBC           0 :             break;
 5294 peter_e@gmx.net           244                 :CBC    10379626 :         w = PQdsplen((const char *) pwcs, encoding);
                                245                 :                : 
 7183 tgl@sss.pgh.pa.us         246         [ +  + ]:       10379626 :         if (chlen == 1)         /* single-byte char */
                                247                 :                :         {
 7267 bruce@momjian.us          248         [ +  + ]:       10377937 :             if (*pwcs == '\n')  /* Newline */
                                249                 :                :             {
 7503                           250         [ +  + ]:          13197 :                 if (linewidth > width)
                                251                 :           3487 :                     width = linewidth;
                                252                 :          13197 :                 linewidth = 0;
                                253                 :          13197 :                 height += 1;
 3354 tgl@sss.pgh.pa.us         254                 :          13197 :                 format_size += 1;   /* For NUL char */
                                255                 :                :             }
                                256         [ +  + ]:       10364740 :             else if (*pwcs == '\r') /* Linefeed */
                                257                 :                :             {
 7503 bruce@momjian.us          258                 :              4 :                 linewidth += 2;
                                259                 :              4 :                 format_size += 2;
                                260                 :                :             }
 3354 tgl@sss.pgh.pa.us         261         [ +  + ]:       10364736 :             else if (*pwcs == '\t') /* Tab */
                                262                 :                :             {
                                263                 :                :                 do
                                264                 :                :                 {
 6684                           265                 :            975 :                     linewidth++;
                                266                 :            975 :                     format_size++;
                                267         [ +  + ]:            975 :                 } while (linewidth % 8 != 0);
                                268                 :                :             }
 7183                           269         [ +  + ]:       10364612 :             else if (w < 0)      /* Other control char */
                                270                 :                :             {
 7503 bruce@momjian.us          271                 :             45 :                 linewidth += 4;
                                272                 :             45 :                 format_size += 4;
                                273                 :                :             }
                                274                 :                :             else                /* Output it as-is */
                                275                 :                :             {
 7183 tgl@sss.pgh.pa.us         276                 :       10364567 :                 linewidth += w;
 7503 bruce@momjian.us          277                 :       10364567 :                 format_size += 1;
                                278                 :                :             }
                                279                 :                :         }
 7183 tgl@sss.pgh.pa.us         280         [ -  + ]:           1689 :         else if (w < 0)          /* Non-ascii control char */
                                281                 :                :         {
 7267 bruce@momjian.us          282                 :UBC           0 :             linewidth += 6;     /* \u0000 */
 7503                           283                 :              0 :             format_size += 6;
                                284                 :                :         }
                                285                 :                :         else                    /* All other chars */
                                286                 :                :         {
 7503 bruce@momjian.us          287                 :CBC        1689 :             linewidth += w;
                                288                 :           1689 :             format_size += chlen;
                                289                 :                :         }
                                290                 :       10379626 :         len -= chlen;
                                291                 :                :     }
                                292         [ +  + ]:         946411 :     if (linewidth > width)
                                293                 :         878978 :         width = linewidth;
 6286                           294                 :         946411 :     format_size += 1;           /* For NUL char */
                                295                 :                : 
                                296                 :                :     /* Set results */
 7503                           297         [ +  + ]:         946411 :     if (result_width)
                                298                 :         946400 :         *result_width = width;
                                299         [ +  - ]:         946411 :     if (result_height)
                                300                 :         946411 :         *result_height = height;
                                301         [ +  + ]:         946411 :     if (result_format_size)
                                302                 :         942112 :         *result_format_size = format_size;
                                303                 :         946411 : }
                                304                 :                : 
                                305                 :                : /*
                                306                 :                :  *  Format a string into one or more "struct lineptr" lines.
                                307                 :                :  *  lines[i].ptr == NULL indicates the end of the array.
                                308                 :                :  *
                                309                 :                :  * This MUST be kept in sync with pg_wcssize!
                                310                 :                :  */
                                311                 :                : void
 5464 peter_e@gmx.net           312                 :         943417 : pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding,
                                313                 :                :              struct lineptr *lines, int count)
                                314                 :                : {
                                315                 :                :     int         w,
 7503 bruce@momjian.us          316                 :         943417 :                 chlen = 0;
 7267                           317                 :         943417 :     int         linewidth = 0;
                                318                 :         943417 :     unsigned char *ptr = lines->ptr; /* Pointer to data area */
                                319                 :                : 
 7503                           320   [ +  +  +  - ]:       11225715 :     for (; *pwcs && len > 0; pwcs += chlen)
                                321                 :                :     {
 5294 peter_e@gmx.net           322                 :       10282298 :         chlen = PQmblen((const char *) pwcs, encoding);
 7267 bruce@momjian.us          323         [ -  + ]:       10282298 :         if (len < (size_t) chlen)
 7503 bruce@momjian.us          324                 :UBC           0 :             break;
 5294 peter_e@gmx.net           325                 :CBC    10282298 :         w = PQdsplen((const char *) pwcs, encoding);
                                326                 :                : 
 7183 tgl@sss.pgh.pa.us         327         [ +  + ]:       10282298 :         if (chlen == 1)         /* single-byte char */
                                328                 :                :         {
 7267 bruce@momjian.us          329         [ +  + ]:       10280609 :             if (*pwcs == '\n')  /* Newline */
                                330                 :                :             {
 7183 tgl@sss.pgh.pa.us         331                 :          13341 :                 *ptr++ = '\0';
 7503 bruce@momjian.us          332                 :          13341 :                 lines->width = linewidth;
                                333                 :          13341 :                 linewidth = 0;
                                334                 :          13341 :                 lines++;
                                335                 :          13341 :                 count--;
 6684 tgl@sss.pgh.pa.us         336         [ -  + ]:          13341 :                 if (count <= 0)
 7267 bruce@momjian.us          337                 :UBC           0 :                     exit(1);    /* Screwup */
                                338                 :                : 
                                339                 :                :                 /* make next line point to remaining memory */
 7503 bruce@momjian.us          340                 :CBC       13341 :                 lines->ptr = ptr;
                                341                 :                :             }
 3354 tgl@sss.pgh.pa.us         342         [ +  + ]:       10267268 :             else if (*pwcs == '\r') /* Linefeed */
                                343                 :                :             {
 7503                           344                 :              4 :                 strcpy((char *) ptr, "\\r");
      bruce@momjian.us          345                 :              4 :                 linewidth += 2;
                                346                 :              4 :                 ptr += 2;
                                347                 :                :             }
 3354 tgl@sss.pgh.pa.us         348         [ +  + ]:       10267264 :             else if (*pwcs == '\t') /* Tab */
                                349                 :                :             {
                                350                 :                :                 do
                                351                 :                :                 {
 6685 bruce@momjian.us          352                 :            975 :                     *ptr++ = ' ';
                                353                 :            975 :                     linewidth++;
                                354         [ +  + ]:            975 :                 } while (linewidth % 8 != 0);
                                355                 :                :             }
 7183 tgl@sss.pgh.pa.us         356         [ +  + ]:       10267140 :             else if (w < 0)      /* Other control char */
                                357                 :                :             {
 7503                           358                 :             45 :                 sprintf((char *) ptr, "\\x%02X", *pwcs);
      bruce@momjian.us          359                 :             45 :                 linewidth += 4;
                                360                 :             45 :                 ptr += 4;
                                361                 :                :             }
                                362                 :                :             else                /* Output it as-is */
                                363                 :                :             {
 7183 tgl@sss.pgh.pa.us         364                 :       10267095 :                 linewidth += w;
 7503 bruce@momjian.us          365                 :       10267095 :                 *ptr++ = *pwcs;
                                366                 :                :             }
                                367                 :                :         }
 7183 tgl@sss.pgh.pa.us         368         [ -  + ]:           1689 :         else if (w < 0)          /* Non-ascii control char */
                                369                 :                :         {
 7503 bruce@momjian.us          370         [ #  # ]:UBC           0 :             if (encoding == PG_UTF8)
 5853 tgl@sss.pgh.pa.us         371                 :              0 :                 sprintf((char *) ptr, "\\u%04X", utf8_to_unicode(pwcs));
                                372                 :                :             else
                                373                 :                :             {
                                374                 :                :                 /*
                                375                 :                :                  * This case cannot happen in the current code because only
                                376                 :                :                  * UTF-8 signals multibyte control characters. But we may need
                                377                 :                :                  * to support it at some stage
                                378                 :                :                  */
 7503                           379                 :              0 :                 sprintf((char *) ptr, "\\u????");
                                380                 :                :             }
      bruce@momjian.us          381                 :              0 :             ptr += 6;
                                382                 :              0 :             linewidth += 6;
                                383                 :                :         }
                                384                 :                :         else                    /* All other chars */
                                385                 :                :         {
                                386                 :                :             int         i;
                                387                 :                : 
 7267 bruce@momjian.us          388         [ +  + ]:CBC        5314 :             for (i = 0; i < chlen; i++)
 7503                           389                 :           3625 :                 *ptr++ = pwcs[i];
                                390                 :           1689 :             linewidth += w;
                                391                 :                :         }
                                392                 :       10282298 :         len -= chlen;
                                393                 :                :     }
                                394                 :         943417 :     lines->width = linewidth;
 6286                           395                 :         943417 :     *ptr++ = '\0';              /* Terminate formatted string */
                                396                 :                : 
 6684 tgl@sss.pgh.pa.us         397         [ -  + ]:         943417 :     if (count <= 0)
 6286 bruce@momjian.us          398                 :UBC           0 :         exit(1);                /* Screwup */
                                399                 :                : 
 6286 bruce@momjian.us          400                 :CBC      943417 :     (lines + 1)->ptr = NULL; /* terminate line array */
 9082 ishii@postgresql.org      401                 :         943417 : }
                                402                 :                : 
                                403                 :                : 
                                404                 :                : /*
                                405                 :                :  * Encoding validation: delete any unvalidatable characters from the string
                                406                 :                :  *
                                407                 :                :  * This seems redundant with existing functionality elsewhere?
                                408                 :                :  */
                                409                 :                : unsigned char *
 7503 bruce@momjian.us          410                 :             16 : mbvalidate(unsigned char *pwcs, int encoding)
                                411                 :                : {
 8563 peter_e@gmx.net           412         [ +  - ]:             16 :     if (encoding == PG_UTF8)
 5277                           413                 :             16 :         mb_utf_validate(pwcs);
                                414                 :                :     else
                                415                 :                :     {
                                416                 :                :         /*
                                417                 :                :          * other encodings needing validation should add their own routines
                                418                 :                :          * here
                                419                 :                :          */
                                420                 :                :     }
                                421                 :                : 
 7642 tgl@sss.pgh.pa.us         422                 :             16 :     return pwcs;
                                423                 :                : }
                                424                 :                : 
                                425                 :                : bool
   16 peter@eisentraut.org      426                 :GNC     2760922 : mb_is_valid(const unsigned char *pwcs, int encoding)
                                427                 :                : {
                                428         [ +  + ]:        2760922 :     if (encoding == PG_UTF8)
                                429                 :        2759230 :         return mb_utf_is_valid(pwcs);
                                430                 :                :     else
                                431                 :                :     {
                                432                 :                :         /*
                                433                 :                :          * other encodings needing validation should add their own routines
                                434                 :                :          * here
                                435                 :                :          */
                                436                 :           1692 :         return true;
                                437                 :                :     }
                                438                 :                : }
        

Generated by: LCOV version 2.0-1