LCOV - differential code coverage report
Current view: top level - src/backend/regex - regc_cvec.c (source / functions) Coverage Total Hit UBC CBC
Current: d36b728949bf4e37ada1cd23e0f2aaa94f609a70 vs 52e118fe2f7e3381bdaa479816a7f72eda2ae517 Lines: 95.0 % 40 38 2 38
Current Date: 2026-06-29 16:15:13 +0200 Functions: 100.0 % 6 6 6
Baseline: lcov-20260630-baseline Branches: 50.0 % 20 10 10 10
Baseline Date: 2026-06-29 13:01:57 +0200 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 95.0 % 40 38 2 38
Function coverage date bins:
(360..) days: 100.0 % 6 6 6
Branch coverage date bins:
(360..) days: 50.0 % 20 10 10 10

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*
                                  2                 :                :  * Utility functions for handling cvecs
                                  3                 :                :  * This file is #included by regcomp.c.
                                  4                 :                :  *
                                  5                 :                :  * Copyright (c) 1998, 1999 Henry Spencer.  All rights reserved.
                                  6                 :                :  *
                                  7                 :                :  * Development of this software was funded, in part, by Cray Research Inc.,
                                  8                 :                :  * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics
                                  9                 :                :  * Corporation, none of whom are responsible for the results.  The author
                                 10                 :                :  * thanks all of them.
                                 11                 :                :  *
                                 12                 :                :  * Redistribution and use in source and binary forms -- with or without
                                 13                 :                :  * modification -- are permitted for any purpose, provided that
                                 14                 :                :  * redistributions in source form retain this entire copyright notice and
                                 15                 :                :  * indicate the origin and nature of any modifications.
                                 16                 :                :  *
                                 17                 :                :  * I'd appreciate being given credit for this package in the documentation
                                 18                 :                :  * of software which uses it, but that is not a requirement.
                                 19                 :                :  *
                                 20                 :                :  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                                 21                 :                :  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                                 22                 :                :  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
                                 23                 :                :  * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                                 24                 :                :  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                                 25                 :                :  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                                 26                 :                :  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                                 27                 :                :  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                                 28                 :                :  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                                 29                 :                :  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                                 30                 :                :  *
                                 31                 :                :  * src/backend/regex/regc_cvec.c
                                 32                 :                :  *
                                 33                 :                :  */
                                 34                 :                : 
                                 35                 :                : /*
                                 36                 :                :  * Notes:
                                 37                 :                :  * Only (selected) functions in _this_ file should treat the chr arrays
                                 38                 :                :  * of a cvec as non-constant.
                                 39                 :                :  */
                                 40                 :                : 
                                 41                 :                : /*
                                 42                 :                :  * newcvec - allocate a new cvec
                                 43                 :                :  *
                                 44                 :                :  * Note: in current usage, nchrs and nranges are never so large that we risk
                                 45                 :                :  * integer overflow in these size calculations, even with 32-bit size_t.
                                 46                 :                :  */
                                 47                 :                : static struct cvec *
 8546 tgl@sss.pgh.pa.us          48                 :CBC        5125 : newcvec(int nchrs,              /* to hold this many chrs... */
                                 49                 :                :         int nranges)            /* ... and this many ranges */
                                 50                 :                : {
 6711                            51                 :           5125 :     size_t      nc = (size_t) nchrs + (size_t) nranges * 2;
                                 52                 :           5125 :     size_t      n = sizeof(struct cvec) + nc * sizeof(chr);
                                 53                 :           5125 :     struct cvec *cv = (struct cvec *) MALLOC(n);
                                 54                 :                : 
 8366 bruce@momjian.us           55         [ -  + ]:           5125 :     if (cv == NULL)
 8366 bruce@momjian.us           56                 :UBC           0 :         return NULL;
 8366 bruce@momjian.us           57                 :CBC        5125 :     cv->chrspace = nchrs;
 6711 tgl@sss.pgh.pa.us          58                 :           5125 :     cv->chrs = (chr *) (((char *) cv) + sizeof(struct cvec));
                                 59                 :           5125 :     cv->ranges = cv->chrs + nchrs;
 8366 bruce@momjian.us           60                 :           5125 :     cv->rangespace = nranges;
                                 61                 :           5125 :     return clearcvec(cv);
                                 62                 :                : }
                                 63                 :                : 
                                 64                 :                : /*
                                 65                 :                :  * clearcvec - clear a possibly-new cvec
                                 66                 :                :  * Returns pointer as convenience.
                                 67                 :                :  */
                                 68                 :                : static struct cvec *
 3296 tgl@sss.pgh.pa.us          69                 :           6509 : clearcvec(struct cvec *cv)
                                 70                 :                : {
 8366 bruce@momjian.us           71         [ -  + ]:           6509 :     assert(cv != NULL);
                                 72                 :           6509 :     cv->nchrs = 0;
                                 73                 :           6509 :     cv->nranges = 0;
 3585 tgl@sss.pgh.pa.us          74                 :           6509 :     cv->cclasscode = -1;
 8366 bruce@momjian.us           75                 :           6509 :     return cv;
                                 76                 :                : }
                                 77                 :                : 
                                 78                 :                : /*
                                 79                 :                :  * addchr - add a chr to a cvec
                                 80                 :                :  */
                                 81                 :                : static void
 3296 tgl@sss.pgh.pa.us          82                 :           2533 : addchr(struct cvec *cv,         /* character vector */
                                 83                 :                :        chr c)                   /* character to add */
                                 84                 :                : {
 5245                            85         [ -  + ]:           2533 :     assert(cv->nchrs < cv->chrspace);
 3602                            86                 :           2533 :     cv->chrs[cv->nchrs++] = c;
 8546                            87                 :           2533 : }
                                 88                 :                : 
                                 89                 :                : /*
                                 90                 :                :  * addrange - add a range to a cvec
                                 91                 :                :  */
                                 92                 :                : static void
 3296                            93                 :            350 : addrange(struct cvec *cv,       /* character vector */
                                 94                 :                :          chr from,              /* first character of range */
                                 95                 :                :          chr to)                /* last character of range */
                                 96                 :                : {
 8366 bruce@momjian.us           97         [ -  + ]:            350 :     assert(cv->nranges < cv->rangespace);
 3602 tgl@sss.pgh.pa.us          98                 :            350 :     cv->ranges[cv->nranges * 2] = from;
                                 99                 :            350 :     cv->ranges[cv->nranges * 2 + 1] = to;
 8366 bruce@momjian.us          100                 :            350 :     cv->nranges++;
 8546 tgl@sss.pgh.pa.us         101                 :            350 : }
                                102                 :                : 
                                103                 :                : /*
                                104                 :                :  * getcvec - get a transient cvec, initialized to empty
                                105                 :                :  *
                                106                 :                :  * The returned cvec is valid only until the next call of getcvec, which
                                107                 :                :  * typically will recycle the space.  Callers should *not* free the cvec
                                108                 :                :  * explicitly; it will be cleaned up when the struct vars is destroyed.
                                109                 :                :  *
                                110                 :                :  * This is typically used while interpreting bracket expressions.  In that
                                111                 :                :  * usage the cvec is only needed momentarily until we build arcs from it,
                                112                 :                :  * so transientness is a convenient behavior.
                                113                 :                :  */
                                114                 :                : static struct cvec *
 3296                           115                 :           1385 : getcvec(struct vars *v,         /* context */
                                116                 :                :         int nchrs,              /* to hold this many chrs... */
                                117                 :                :         int nranges)            /* ... and this many ranges */
                                118                 :                : {
                                119                 :                :     /* recycle existing transient cvec if large enough */
 8366 bruce@momjian.us          120   [ +  -  +  + ]:           1385 :     if (v->cv != NULL && nchrs <= v->cv->chrspace &&
 6711 tgl@sss.pgh.pa.us         121         [ +  - ]:           1384 :         nranges <= v->cv->rangespace)
 8366 bruce@momjian.us          122                 :           1384 :         return clearcvec(v->cv);
                                123                 :                : 
                                124                 :                :     /* nope, make a new one */
                                125         [ +  - ]:              1 :     if (v->cv != NULL)
                                126                 :              1 :         freecvec(v->cv);
 6711 tgl@sss.pgh.pa.us         127                 :              1 :     v->cv = newcvec(nchrs, nranges);
 8366 bruce@momjian.us          128         [ -  + ]:              1 :     if (v->cv == NULL)
 8366 bruce@momjian.us          129         [ #  # ]:UBC           0 :         ERR(REG_ESPACE);
                                130                 :                : 
 8366 bruce@momjian.us          131                 :CBC           1 :     return v->cv;
                                132                 :                : }
                                133                 :                : 
                                134                 :                : /*
                                135                 :                :  * freecvec - free a cvec
                                136                 :                :  */
                                137                 :                : static void
 3296 tgl@sss.pgh.pa.us         138                 :           5125 : freecvec(struct cvec *cv)
                                139                 :                : {
 8366 bruce@momjian.us          140                 :           5125 :     FREE(cv);
 8546 tgl@sss.pgh.pa.us         141                 :           5125 : }
        

Generated by: LCOV version 2.0-1