~ubuntu-branches/ubuntu/trusty/postgresql-9.3/trusty-proposed

« back to all changes in this revision

Viewing changes to src/backend/utils/adt/varlena.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-07-24 16:13:59 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140724161359-uk325qfv03euxuuh
Tags: 9.3.5-0ubuntu0.14.04.1
* New upstream bug fix release: (LP: #1348176)
  - pg_upgrade: Users who upgraded to version 9.3 using pg_upgrade may have
    an issue with transaction information which causes VACUUM to eventually
    fail. These users should run the script provided in the release notes to
    determine if their installation is affected, and then take the remedy
    steps outlined there.
  - Various data integrity and other bug fixes.
  - Secure Unix-domain sockets of temporary postmasters started during make
    check.
    Any local user able to access the socket file could connect as the
    server's bootstrap superuser, then proceed to execute arbitrary code as
    the operating-system user running the test, as we previously noted in
    CVE-2014-0067. This change defends against that risk by placing the
    server's socket in a temporary, mode 0700 subdirectory of /tmp.
  - See release notes for details:
    http://www.postgresql.org/about/news/1534/
* Remove pg_regress patches to support --host=/path, obsolete with above
  upstream changes and not applicable any more.
* Drop tcl8.6 patch, applied upstream.
* Add missing logrotate test dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
591
591
 *      Does the real work for textlen()
592
592
 *
593
593
 *      This is broken out so it can be called directly by other string processing
594
 
 *      functions.      Note that the argument is passed as a Datum, to indicate that
 
594
 *      functions.  Note that the argument is passed as a Datum, to indicate that
595
595
 *      it may still be in compressed form.  We can avoid decompressing it at all
596
596
 *      in some cases.
597
597
 */
763
763
 *      Does the real work for text_substr() and text_substr_no_len()
764
764
 *
765
765
 *      This is broken out so it can be called directly by other string processing
766
 
 *      functions.      Note that the argument is passed as a Datum, to indicate that
 
766
 *      functions.  Note that the argument is passed as a Datum, to indicate that
767
767
 *      it may still be in compressed/toasted form.  We can avoid detoasting all
768
768
 *      of it in some cases.
769
769
 *
1113
1113
         * searched (t1) and the "needle" is the pattern being sought (t2).
1114
1114
         *
1115
1115
         * If the needle is empty or bigger than the haystack then there is no
1116
 
         * point in wasting cycles initializing the table.      We also choose not to
 
1116
         * point in wasting cycles initializing the table.  We also choose not to
1117
1117
         * use B-M-H for needles of length 1, since the skip table can't possibly
1118
1118
         * save anything in that case.
1119
1119
         */
1129
1129
                 * declaration of TextPositionState allows up to 256 elements, but for
1130
1130
                 * short search problems we don't really want to have to initialize so
1131
1131
                 * many elements --- it would take too long in comparison to the
1132
 
                 * actual search time.  So we choose a useful skip table size based on
 
1132
                 * actual search time.  So we choose a useful skip table size based on
1133
1133
                 * the haystack length minus the needle length.  The closer the needle
1134
1134
                 * length is to the haystack length the less useful skipping becomes.
1135
1135
                 *
1161
1161
                        state->skiptable[i] = len2;
1162
1162
 
1163
1163
                /*
1164
 
                 * Now examine the needle.      For each character except the last one,
 
1164
                 * Now examine the needle.  For each character except the last one,
1165
1165
                 * set the corresponding table element to the appropriate skip
1166
1166
                 * distance.  Note that when two characters share the same skip table
1167
1167
                 * entry, the one later in the needle must determine the skip
1249
1249
 
1250
1250
                                /*
1251
1251
                                 * No match, so use the haystack char at hptr to decide how
1252
 
                                 * far to advance.      If the needle had any occurrence of that
 
1252
                                 * far to advance.  If the needle had any occurrence of that
1253
1253
                                 * character (or more precisely, one sharing the same
1254
1254
                                 * skiptable entry) before its last character, then we advance
1255
1255
                                 * far enough to align the last such needle character with
1256
 
                                 * that haystack position.      Otherwise we can advance by the
 
1256
                                 * that haystack position.  Otherwise we can advance by the
1257
1257
                                 * whole needle length.
1258
1258
                                 */
1259
1259
                                hptr += state->skiptable[(unsigned char) *hptr & skiptablemask];
1305
1305
 
1306
1306
                                /*
1307
1307
                                 * No match, so use the haystack char at hptr to decide how
1308
 
                                 * far to advance.      If the needle had any occurrence of that
 
1308
                                 * far to advance.  If the needle had any occurrence of that
1309
1309
                                 * character (or more precisely, one sharing the same
1310
1310
                                 * skiptable entry) before its last character, then we advance
1311
1311
                                 * far enough to align the last such needle character with
1312
 
                                 * that haystack position.      Otherwise we can advance by the
 
1312
                                 * that haystack position.  Otherwise we can advance by the
1313
1313
                                 * whole needle length.
1314
1314
                                 */
1315
1315
                                hptr += state->skiptable[*hptr & skiptablemask];
1344
1344
 
1345
1345
        /*
1346
1346
         * Unfortunately, there is no strncoll(), so in the non-C locale case we
1347
 
         * have to do some memory copying.      This turns out to be significantly
 
1347
         * have to do some memory copying.  This turns out to be significantly
1348
1348
         * slower, so we optimize the case where LC_COLLATE is C.  We also try to
1349
1349
         * optimize relatively-short strings by avoiding palloc/pfree overhead.
1350
1350
         */
2334
2334
 * SplitIdentifierString --- parse a string containing identifiers
2335
2335
 *
2336
2336
 * This is the guts of textToQualifiedNameList, and is exported for use in
2337
 
 * other situations such as parsing GUC variables.      In the GUC case, it's
 
2337
 * other situations such as parsing GUC variables.  In the GUC case, it's
2338
2338
 * important to avoid memory leaks, so the API is designed to minimize the
2339
2339
 * amount of stuff that needs to be allocated and freed.
2340
2340
 *
2342
2342
 *      rawstring: the input string; must be overwritable!      On return, it's
2343
2343
 *                         been modified to contain the separated identifiers.
2344
2344
 *      separator: the separator punctuation expected between identifiers
2345
 
 *                         (typically '.' or ',').      Whitespace may also appear around
 
2345
 *                         (typically '.' or ',').  Whitespace may also appear around
2346
2346
 *                         identifiers.
2347
2347
 * Outputs:
2348
2348
 *      namelist: filled with a palloc'd list of pointers to identifiers within
2411
2411
                         *
2412
2412
                         * XXX because we want to overwrite the input in-place, we cannot
2413
2413
                         * support a downcasing transformation that increases the string
2414
 
                         * length.      This is not a problem given the current implementation
 
2414
                         * length.  This is not a problem given the current implementation
2415
2415
                         * of downcase_truncate_identifier, but we'll probably have to do
2416
2416
                         * something about this someday.
2417
2417
                         */
2468
2468
 * Inputs:
2469
2469
 *      rawstring: the input string; must be modifiable!
2470
2470
 *      separator: the separator punctuation expected between directories
2471
 
 *                         (typically ',' or ';').      Whitespace may also appear around
 
2471
 *                         (typically ',' or ';').  Whitespace may also appear around
2472
2472
 *                         directories.
2473
2473
 * Outputs:
2474
2474
 *      namelist: filled with a palloc'd list of directory names.
2875
2875
 * appendStringInfoRegexpSubstr
2876
2876
 *
2877
2877
 * Append replace_text to str, substituting regexp back references for
2878
 
 * \n escapes.  start_ptr is the start of the match in the source string,
 
2878
 * \n escapes.  start_ptr is the start of the match in the source string,
2879
2879
 * at logical character position data_pos.
2880
2880
 */
2881
2881
static void
2958
2958
                if (so != -1 && eo != -1)
2959
2959
                {
2960
2960
                        /*
2961
 
                         * Copy the text that is back reference of regexp.      Note so and eo
 
2961
                         * Copy the text that is back reference of regexp.  Note so and eo
2962
2962
                         * are counted in characters not bytes.
2963
2963
                         */
2964
2964
                        char       *chunk_start;
4249
4249
 
4250
4250
                /*
4251
4251
                 * Get the appropriate typOutput function, reusing previous one if
4252
 
                 * same type as previous argument.      That's particularly useful in the
 
4252
                 * same type as previous argument.  That's particularly useful in the
4253
4253
                 * variadic-array case, but often saves work even for ordinary calls.
4254
4254
                 */
4255
4255
                if (typid != prev_type)
4341
4341
 *
4342
4342
 * Inputs are start_ptr (the position after '%') and end_ptr (string end + 1).
4343
4343
 * Output parameters:
4344
 
 *      argpos: argument position for value to be printed.      -1 means unspecified.
4345
 
 *      widthpos: argument position for width.  Zero means the argument position
 
4344
 *      argpos: argument position for value to be printed.  -1 means unspecified.
 
4345
 *      widthpos: argument position for width.  Zero means the argument position
4346
4346
 *                      was unspecified (ie, take the next arg) and -1 means no width
4347
4347
 *                      argument (width was omitted or specified as a constant).
4348
4348
 *      flags: bitmask of flags.
4349
 
 *      width: directly-specified width value.  Zero means the width was omitted
 
4349
 *      width: directly-specified width value.  Zero means the width was omitted
4350
4350
 *                      (note it's not necessary to distinguish this case from an explicit
4351
4351
 *                      zero width value).
4352
4352
 *