LCOV - differential code coverage report
Current view: top level - src/backend/regex - regerror.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 40.0 % 35 14 21 14
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 1 1 1
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (240..) days: 40.0 % 35 14 21 14
Legend: Lines: hit not hit Function coverage date bins:
(240..) days: 100.0 % 1 1 1

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*
                                  2                 :  * regerror - error-code expansion
                                  3                 :  *
                                  4                 :  * Copyright (c) 1998, 1999 Henry Spencer.  All rights reserved.
                                  5                 :  *
                                  6                 :  * Development of this software was funded, in part, by Cray Research Inc.,
                                  7                 :  * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics
                                  8                 :  * Corporation, none of whom are responsible for the results.  The author
                                  9                 :  * thanks all of them.
                                 10                 :  *
                                 11                 :  * Redistribution and use in source and binary forms -- with or without
                                 12                 :  * modification -- are permitted for any purpose, provided that
                                 13                 :  * redistributions in source form retain this entire copyright notice and
                                 14                 :  * indicate the origin and nature of any modifications.
                                 15                 :  *
                                 16                 :  * I'd appreciate being given credit for this package in the documentation
                                 17                 :  * of software which uses it, but that is not a requirement.
                                 18                 :  *
                                 19                 :  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                                 20                 :  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                                 21                 :  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
                                 22                 :  * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                                 23                 :  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                                 24                 :  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                                 25                 :  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                                 26                 :  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                                 27                 :  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                                 28                 :  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                                 29                 :  *
                                 30                 :  * src/backend/regex/regerror.c
                                 31                 :  *
                                 32                 :  */
                                 33                 : 
                                 34                 : #include "regex/regguts.h"
                                 35                 : 
                                 36                 : /* unknown-error explanation */
                                 37                 : static const char unk[] = "*** unknown regex error code 0x%x ***";
                                 38                 : 
                                 39                 : /* struct to map among codes, code names, and explanations */
                                 40                 : static const struct rerr
                                 41                 : {
                                 42                 :     int         code;
                                 43                 :     const char *name;
                                 44                 :     const char *explain;
                                 45                 : }           rerrs[] =
                                 46                 : 
                                 47                 : {
                                 48                 :     /* the actual table is built from regex.h */
                                 49                 : #include "regex/regerrs.h"        /* pgrminclude ignore */
                                 50                 :     {
                                 51                 :         -1, "", "oops"
                                 52                 :     },                          /* explanation special-cased in code */
                                 53                 : };
                                 54                 : 
                                 55                 : /*
                                 56                 :  * pg_regerror - the interface to error numbers
                                 57                 :  */
                                 58                 : /* ARGSUSED */
                                 59                 : size_t                          /* actual space needed (including NUL) */
 7368 tgl                        60 CBC         127 : pg_regerror(int errcode,        /* error code, or REG_ATOI or REG_ITOA */
                                 61                 :             const regex_t *preg,    /* associated regex_t (unused at present) */
                                 62                 :             char *errbuf,       /* result buffer (unless errbuf_size==0) */
                                 63                 :             size_t errbuf_size) /* available space in errbuf, can be 0 */
                                 64                 : {
                                 65                 :     const struct rerr *r;
                                 66                 :     const char *msg;
                                 67                 :     char        convbuf[sizeof(unk) + 50];  /* 50 = plenty for int */
                                 68                 :     size_t      len;
                                 69                 :     int         icode;
                                 70                 : 
 7188 bruce                      71             127 :     switch (errcode)
                                 72                 :     {
 7188 bruce                      73 UBC           0 :         case REG_ATOI:          /* convert name to number */
                                 74               0 :             for (r = rerrs; r->code >= 0; r++)
                                 75               0 :                 if (strcmp(r->name, errbuf) == 0)
                                 76               0 :                     break;
                                 77               0 :             sprintf(convbuf, "%d", r->code);   /* -1 for unknown */
 7368 tgl                        78               0 :             msg = convbuf;
 7188 bruce                      79               0 :             break;
                                 80               0 :         case REG_ITOA:          /* convert number to name */
 2118 tgl                        81               0 :             icode = atoi(errbuf);   /* not our problem if this fails */
 7188 bruce                      82               0 :             for (r = rerrs; r->code >= 0; r++)
                                 83               0 :                 if (r->code == icode)
                                 84               0 :                     break;
                                 85               0 :             if (r->code >= 0)
                                 86               0 :                 msg = r->name;
                                 87                 :             else
                                 88                 :             {                   /* unknown; tell him the number */
                                 89               0 :                 sprintf(convbuf, "REG_%u", (unsigned) icode);
                                 90               0 :                 msg = convbuf;
                                 91                 :             }
                                 92               0 :             break;
 7188 bruce                      93 CBC         127 :         default:                /* a real, normal error code */
                                 94            1320 :             for (r = rerrs; r->code >= 0; r++)
                                 95            1320 :                 if (r->code == errcode)
                                 96             127 :                     break;
                                 97             127 :             if (r->code >= 0)
                                 98             127 :                 msg = r->explain;
                                 99                 :             else
                                100                 :             {                   /* unknown; say so */
 7188 bruce                     101 UBC           0 :                 sprintf(convbuf, unk, errcode);
                                102               0 :                 msg = convbuf;
                                103                 :             }
 7188 bruce                     104 CBC         127 :             break;
                                105                 :     }
                                106                 : 
 7368 tgl                       107             127 :     len = strlen(msg) + 1;      /* space needed, including NUL */
 7188 bruce                     108             127 :     if (errbuf_size > 0)
                                109                 :     {
 9770 scrappy                   110             127 :         if (errbuf_size > len)
 7368 tgl                       111             127 :             strcpy(errbuf, msg);
                                112                 :         else
                                113                 :         {                       /* truncate to fit */
 2997 tgl                       114 UBC           0 :             memcpy(errbuf, msg, errbuf_size - 1);
 7188 bruce                     115               0 :             errbuf[errbuf_size - 1] = '\0';
                                116                 :         }
                                117                 :     }
                                118                 : 
 8986 bruce                     119 CBC         127 :     return len;
                                120                 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a