Coverage Report

Created: 2026-10-05 06:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pcre2/src/pcre2_context.c
Line
Count
Source
1
/*************************************************
2
*      Perl-Compatible Regular Expressions       *
3
*************************************************/
4
5
/* PCRE is a library of functions to support regular expressions whose syntax
6
and semantics are as close as possible to those of the Perl 5 language.
7
8
                       Written by Philip Hazel
9
     Original API code Copyright (c) 1997-2012 University of Cambridge
10
          New API code Copyright (c) 2016-2024 University of Cambridge
11
12
-----------------------------------------------------------------------------
13
Redistribution and use in source and binary forms, with or without
14
modification, are permitted provided that the following conditions are met:
15
16
    * Redistributions of source code must retain the above copyright notice,
17
      this list of conditions and the following disclaimer.
18
19
    * Redistributions in binary form must reproduce the above copyright
20
      notice, this list of conditions and the following disclaimer in the
21
      documentation and/or other materials provided with the distribution.
22
23
    * Neither the name of the University of Cambridge nor the names of its
24
      contributors may be used to endorse or promote products derived from
25
      this software without specific prior written permission.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
POSSIBILITY OF SUCH DAMAGE.
38
-----------------------------------------------------------------------------
39
*/
40
41
42
#include "pcre2_internal.h"
43
44
45
46
/*************************************************
47
*          Default malloc/free functions         *
48
*************************************************/
49
50
/* Ignore the "user data" argument in each case. */
51
52
static void *
53
default_malloc(size_t size, void *data)
54
9.31M
{
55
9.31M
  (void)data;
56
9.31M
  return malloc(size);
57
9.31M
}
58
59
60
static void
61
default_free(void *block, void *data)
62
9.49M
{
63
9.49M
  (void)data;
64
9.49M
  free(block);
65
9.49M
}
66
67
68
69
/*************************************************
70
*        Get a block and save memory control     *
71
*************************************************/
72
73
/* This internal function is called to get a block of memory in which the
74
memory control data is to be stored at the start for future use.
75
76
Arguments:
77
  size        amount of memory required
78
  memctl      pointer to a memctl block or NULL
79
80
Returns:      pointer to memory or NULL on failure
81
*/
82
83
extern void *
84
PRIV(memctl_malloc)(size_t size, pcre2_memctl *memctl)
85
122k
{
86
122k
  void *yield = (memctl == NULL) ? malloc(size) : memctl->malloc(size, memctl->memory_data);
87
122k
  if (yield == NULL)
88
0
    return NULL;
89
90
122k
  pcre2_memctl *newmemctl = (pcre2_memctl *)yield;
91
122k
  if (memctl == NULL)
92
122k
  {
93
122k
    newmemctl->malloc = default_malloc;
94
122k
    newmemctl->free = default_free;
95
122k
    newmemctl->memory_data = NULL;
96
122k
  }
97
0
  else
98
0
  {
99
0
    *newmemctl = *memctl;
100
0
  }
101
102
122k
  return yield;
103
122k
}
104
105
106
107
/*************************************************
108
*          Create and initialize contexts        *
109
*************************************************/
110
111
/* Specialized contexts copy static default templates, replacing the memory
112
management functions when a general context is supplied. */
113
114
PCRE2_EXP_DEFN pcre2_general_context *PCRE2_CALL_CONVENTION
115
pcre2_general_context_create(void *(*private_malloc)(size_t size, void *memory_data),
116
                             void (*private_free)(void *ptr, void *memory_data), void *memory_data)
117
0
{
118
0
  if (private_malloc == NULL)
119
0
    private_malloc = default_malloc;
120
0
  if (private_free == NULL)
121
0
    private_free = default_free;
122
123
0
  pcre2_general_context *gcontext = private_malloc(sizeof(pcre2_real_general_context), memory_data);
124
0
  if (gcontext == NULL)
125
0
    return NULL;
126
127
0
  gcontext->memctl.malloc = private_malloc;
128
0
  gcontext->memctl.free = private_free;
129
0
  gcontext->memctl.memory_data = memory_data;
130
0
  return gcontext;
131
0
}
132
133
134
/* A default compile context is set up to save having to initialize at run time
135
when no context is supplied to the compile function. */
136
137
pcre2_compile_context PRIV(default_compile_context) = {
138
  { default_malloc, default_free, NULL }, // Default memory handling
139
  NULL,                                   // Stack guard
140
  NULL,                                   // Stack guard data
141
  PRIV(default_tables),                   // Character tables
142
  PCRE2_UNSET,                            // Max pattern length
143
  PCRE2_UNSET,                            // Max pattern compiled length
144
  BSR_DEFAULT,                            // Backslash R default
145
  NEWLINE_DEFAULT,                        // Newline convention
146
  PARENS_NEST_LIMIT,                      // As it says
147
  0,                                      // Extra options
148
  MAX_VARLOOKBEHIND,                      // As it says
149
  PCRE2_OPTIMIZATION_ALL,                 // All optimizations enabled
150
};
151
152
/* The create function copies the default into the new memory, but must
153
override the default memory handling functions if a gcontext was provided. */
154
155
PCRE2_EXP_DEFN pcre2_compile_context *PCRE2_CALL_CONVENTION
156
pcre2_compile_context_create(pcre2_general_context *gcontext)
157
32.8k
{
158
32.8k
  pcre2_compile_context *ccontext =
159
32.8k
      PRIV(memctl_malloc)(sizeof(pcre2_real_compile_context), (pcre2_memctl *)gcontext);
160
32.8k
  if (ccontext == NULL)
161
0
    return NULL;
162
163
32.8k
  *ccontext = PRIV(default_compile_context);
164
32.8k
  if (gcontext != NULL)
165
0
    ccontext->memctl = gcontext->memctl;
166
32.8k
  return ccontext;
167
32.8k
}
168
169
170
/* A default match context is set up to save having to initialize at run time
171
when no context is supplied to a match function. */
172
173
pcre2_match_context PRIV(default_match_context) = {
174
  { default_malloc, default_free, NULL },
175
#ifdef SUPPORT_JIT
176
  NULL, // JIT callback
177
  NULL, // JIT callback data
178
#endif
179
  NULL,        // Callout function
180
  NULL,        // Callout data
181
  NULL,        // Substitute callout function
182
  NULL,        // Substitute callout data
183
  NULL,        // Substitute case callout function
184
  NULL,        // Substitute case callout data
185
  PCRE2_UNSET, // Offset limit
186
  HEAP_LIMIT,
187
  MATCH_LIMIT,
188
  MATCH_LIMIT_DEPTH,
189
};
190
191
/* The create function copies the default into the new memory, but must
192
override the default memory handling functions if a gcontext was provided. */
193
194
PCRE2_EXP_DEFN pcre2_match_context *PCRE2_CALL_CONVENTION
195
pcre2_match_context_create(pcre2_general_context *gcontext)
196
29.8k
{
197
29.8k
  pcre2_match_context *mcontext =
198
29.8k
      PRIV(memctl_malloc)(sizeof(pcre2_real_match_context), (pcre2_memctl *)gcontext);
199
29.8k
  if (mcontext == NULL)
200
0
    return NULL;
201
202
29.8k
  *mcontext = PRIV(default_match_context);
203
29.8k
  if (gcontext != NULL)
204
0
    mcontext->memctl = gcontext->memctl;
205
29.8k
  return mcontext;
206
29.8k
}
207
208
209
/* A default convert context is set up to save having to initialize at run time
210
when no context is supplied to the convert function. */
211
212
pcre2_convert_context PRIV(default_convert_context) = {
213
  { default_malloc, default_free, NULL }, // Default memory handling
214
#ifdef _WIN32
215
  CHAR_BACKSLASH,    // Default path separator
216
  CHAR_GRAVE_ACCENT, // Default escape character
217
#else                /* Not Windows */
218
  CHAR_SLASH,     // Default path separator
219
  CHAR_BACKSLASH, // Default escape character
220
#endif
221
};
222
223
/* The create function copies the default into the new memory, but must
224
override the default memory handling functions if a gcontext was provided. */
225
226
PCRE2_EXP_DEFN pcre2_convert_context *PCRE2_CALL_CONVENTION
227
pcre2_convert_context_create(pcre2_general_context *gcontext)
228
0
{
229
0
  pcre2_convert_context *ccontext =
230
0
      PRIV(memctl_malloc)(sizeof(pcre2_real_convert_context), (pcre2_memctl *)gcontext);
231
0
  if (ccontext == NULL)
232
0
    return NULL;
233
234
0
  *ccontext = PRIV(default_convert_context);
235
0
  if (gcontext != NULL)
236
0
    ccontext->memctl = gcontext->memctl;
237
0
  return ccontext;
238
0
}
239
240
241
/*************************************************
242
*              Context copy functions            *
243
*************************************************/
244
245
PCRE2_EXP_DEFN pcre2_general_context *PCRE2_CALL_CONVENTION
246
pcre2_general_context_copy(pcre2_general_context *gcontext)
247
0
{
248
0
  if (gcontext == NULL)
249
0
    return NULL;
250
251
0
  pcre2_general_context *newcontext =
252
0
      gcontext->memctl.malloc(sizeof(pcre2_real_general_context), gcontext->memctl.memory_data);
253
0
  if (newcontext == NULL)
254
0
    return NULL;
255
256
0
  memcpy(newcontext, gcontext, sizeof(pcre2_real_general_context));
257
0
  return newcontext;
258
0
}
259
260
261
PCRE2_EXP_DEFN pcre2_compile_context *PCRE2_CALL_CONVENTION
262
pcre2_compile_context_copy(pcre2_compile_context *ccontext)
263
0
{
264
0
  if (ccontext == NULL)
265
0
    return NULL;
266
267
0
  pcre2_compile_context *newcontext =
268
0
      ccontext->memctl.malloc(sizeof(pcre2_real_compile_context), ccontext->memctl.memory_data);
269
0
  if (newcontext == NULL)
270
0
    return NULL;
271
272
0
  memcpy(newcontext, ccontext, sizeof(pcre2_real_compile_context));
273
0
  return newcontext;
274
0
}
275
276
277
PCRE2_EXP_DEFN pcre2_match_context *PCRE2_CALL_CONVENTION
278
pcre2_match_context_copy(pcre2_match_context *mcontext)
279
0
{
280
0
  if (mcontext == NULL)
281
0
    return NULL;
282
283
0
  pcre2_match_context *newcontext =
284
0
      mcontext->memctl.malloc(sizeof(pcre2_real_match_context), mcontext->memctl.memory_data);
285
0
  if (newcontext == NULL)
286
0
    return NULL;
287
288
0
  memcpy(newcontext, mcontext, sizeof(pcre2_real_match_context));
289
0
  return newcontext;
290
0
}
291
292
293
PCRE2_EXP_DEFN pcre2_convert_context *PCRE2_CALL_CONVENTION
294
pcre2_convert_context_copy(pcre2_convert_context *ccontext)
295
0
{
296
0
  if (ccontext == NULL)
297
0
    return NULL;
298
299
0
  pcre2_convert_context *newcontext =
300
0
      ccontext->memctl.malloc(sizeof(pcre2_real_convert_context), ccontext->memctl.memory_data);
301
0
  if (newcontext == NULL)
302
0
    return NULL;
303
304
0
  memcpy(newcontext, ccontext, sizeof(pcre2_real_convert_context));
305
0
  return newcontext;
306
0
}
307
308
309
/*************************************************
310
*              Context free functions            *
311
*************************************************/
312
313
PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
314
pcre2_general_context_free(pcre2_general_context *gcontext)
315
0
{
316
0
  if (gcontext != NULL)
317
0
    gcontext->memctl.free(gcontext, gcontext->memctl.memory_data);
318
0
}
319
320
321
PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
322
pcre2_compile_context_free(pcre2_compile_context *ccontext)
323
32.8k
{
324
32.8k
  if (ccontext != NULL)
325
32.8k
    ccontext->memctl.free(ccontext, ccontext->memctl.memory_data);
326
32.8k
}
327
328
329
PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
330
pcre2_match_context_free(pcre2_match_context *mcontext)
331
29.8k
{
332
29.8k
  if (mcontext != NULL)
333
29.8k
    mcontext->memctl.free(mcontext, mcontext->memctl.memory_data);
334
29.8k
}
335
336
337
PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
338
pcre2_convert_context_free(pcre2_convert_context *ccontext)
339
0
{
340
0
  if (ccontext != NULL)
341
0
    ccontext->memctl.free(ccontext, ccontext->memctl.memory_data);
342
0
}
343
344
345
/*************************************************
346
*             Set values in contexts             *
347
*************************************************/
348
349
/* Setters and getters require a non-NULL context and return 0 for success.
350
Functions that validate their data return PCRE2_ERROR_BADDATA, or
351
PCRE2_ERROR_BADOPTION in the case of pcre2_set_optimize(). Only some of the
352
functions are able to test the validity of the data. */
353
354
355
/* ------------ Compile context ------------ */
356
357
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
358
pcre2_set_character_tables(pcre2_compile_context *ccontext, const uint8_t *tables)
359
0
{
360
0
  PCRE2_ASSERT(ccontext != NULL);
361
0
  ccontext->tables = tables;
362
0
  return 0;
363
0
}
364
365
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
366
pcre2_set_bsr(pcre2_compile_context *ccontext, uint32_t value)
367
0
{
368
0
  PCRE2_ASSERT(ccontext != NULL);
369
0
  switch (value)
370
0
  {
371
0
  case PCRE2_BSR_ANYCRLF:
372
0
  case PCRE2_BSR_UNICODE:
373
0
    ccontext->bsr_convention = value;
374
0
    return 0;
375
376
0
  default:
377
0
    return PCRE2_ERROR_BADDATA;
378
0
  }
379
0
}
380
381
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
382
pcre2_get_bsr(pcre2_compile_context *ccontext, uint32_t *value)
383
0
{
384
0
  PCRE2_ASSERT(ccontext != NULL);
385
0
  PCRE2_ASSERT(value != NULL);
386
0
  *value = ccontext->bsr_convention;
387
0
  return 0;
388
0
}
389
390
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
391
pcre2_get_max_pattern_length(pcre2_compile_context *ccontext, PCRE2_SIZE *length)
392
0
{
393
0
  PCRE2_ASSERT(ccontext != NULL);
394
0
  PCRE2_ASSERT(length != NULL);
395
0
  *length = ccontext->max_pattern_length;
396
0
  return 0;
397
0
}
398
399
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
400
pcre2_set_max_pattern_length(pcre2_compile_context *ccontext, PCRE2_SIZE length)
401
0
{
402
0
  PCRE2_ASSERT(ccontext != NULL);
403
0
  ccontext->max_pattern_length = length;
404
0
  return 0;
405
0
}
406
407
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
408
pcre2_set_max_pattern_compiled_length(pcre2_compile_context *ccontext, PCRE2_SIZE length)
409
32.8k
{
410
32.8k
  PCRE2_ASSERT(ccontext != NULL);
411
32.8k
  ccontext->max_pattern_compiled_length = length;
412
32.8k
  return 0;
413
32.8k
}
414
415
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
416
pcre2_set_newline(pcre2_compile_context *ccontext, uint32_t newline)
417
0
{
418
0
  PCRE2_ASSERT(ccontext != NULL);
419
0
  switch (newline)
420
0
  {
421
0
  case PCRE2_NEWLINE_CR:
422
0
  case PCRE2_NEWLINE_LF:
423
0
  case PCRE2_NEWLINE_CRLF:
424
0
  case PCRE2_NEWLINE_ANY:
425
0
  case PCRE2_NEWLINE_ANYCRLF:
426
0
  case PCRE2_NEWLINE_NUL:
427
0
    ccontext->newline_convention = newline;
428
0
    return 0;
429
430
0
  default:
431
0
    return PCRE2_ERROR_BADDATA;
432
0
  }
433
0
}
434
435
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
436
pcre2_get_newline(pcre2_compile_context *ccontext, uint32_t *newline)
437
0
{
438
0
  PCRE2_ASSERT(ccontext != NULL);
439
0
  PCRE2_ASSERT(newline != NULL);
440
0
  *newline = ccontext->newline_convention;
441
0
  return 0;
442
0
}
443
444
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
445
pcre2_set_max_varlookbehind(pcre2_compile_context *ccontext, uint32_t limit)
446
0
{
447
0
  PCRE2_ASSERT(ccontext != NULL);
448
0
  ccontext->max_varlookbehind = limit;
449
0
  return 0;
450
0
}
451
452
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
453
pcre2_get_parens_nest_limit(pcre2_compile_context *ccontext, uint32_t *limit)
454
0
{
455
0
  PCRE2_ASSERT(ccontext != NULL);
456
0
  PCRE2_ASSERT(limit != NULL);
457
0
  *limit = ccontext->parens_nest_limit;
458
0
  return 0;
459
0
}
460
461
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
462
pcre2_set_parens_nest_limit(pcre2_compile_context *ccontext, uint32_t limit)
463
0
{
464
0
  PCRE2_ASSERT(ccontext != NULL);
465
0
  ccontext->parens_nest_limit = limit;
466
0
  return 0;
467
0
}
468
469
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
470
pcre2_set_compile_extra_options(pcre2_compile_context *ccontext, uint32_t options)
471
0
{
472
0
  PCRE2_ASSERT(ccontext != NULL);
473
0
  ccontext->extra_options = options;
474
0
  return 0;
475
0
}
476
477
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
478
pcre2_set_compile_recursion_guard(pcre2_compile_context *ccontext,
479
                                  int (*guard)(uint32_t depth, void *user_data), void *user_data)
480
0
{
481
0
  PCRE2_ASSERT(ccontext != NULL);
482
0
  ccontext->stack_guard = guard;
483
0
  ccontext->stack_guard_data = user_data;
484
0
  return 0;
485
0
}
486
487
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
488
pcre2_set_optimize(pcre2_compile_context *ccontext, uint32_t directive)
489
0
{
490
0
  PCRE2_ASSERT(ccontext != NULL);
491
492
0
  switch (directive)
493
0
  {
494
0
  case PCRE2_OPTIMIZATION_NONE:
495
0
    ccontext->optimization_flags = 0;
496
0
    break;
497
498
0
  case PCRE2_OPTIMIZATION_FULL:
499
0
    ccontext->optimization_flags = PCRE2_OPTIMIZATION_ALL;
500
0
    break;
501
502
0
  default:
503
0
    if (directive >= PCRE2_AUTO_POSSESS && directive <= PCRE2_START_OPTIMIZE_OFF)
504
0
    {
505
      /* Even directive numbers starting from 64 switch a bit on;
506
       * Odd directive numbers starting from 65 switch a bit off */
507
0
      if ((directive & 1) != 0)
508
0
        ccontext->optimization_flags &= ~(1u << ((directive >> 1) - 32));
509
0
      else
510
0
        ccontext->optimization_flags |= 1u << ((directive >> 1) - 32);
511
0
      return 0;
512
0
    }
513
514
0
    return PCRE2_ERROR_BADOPTION;
515
0
  }
516
517
0
  return 0;
518
0
}
519
520
/* ------------ Match context ------------ */
521
522
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
523
pcre2_set_callout(pcre2_match_context *mcontext,
524
                  int (*callout)(pcre2_callout_block *callout_block, void *callout_data),
525
                  void *callout_data)
526
29.8k
{
527
29.8k
  PCRE2_ASSERT(mcontext != NULL);
528
29.8k
  mcontext->callout = callout;
529
29.8k
  mcontext->callout_data = callout_data;
530
29.8k
  return 0;
531
29.8k
}
532
533
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
534
pcre2_set_substitute_callout(
535
    pcre2_match_context *mcontext,
536
    int (*substitute_callout)(pcre2_substitute_callout_block *callout_block,
537
                              void *substitute_callout_data),
538
    void *substitute_callout_data)
539
0
{
540
0
  PCRE2_ASSERT(mcontext != NULL);
541
0
  mcontext->substitute_callout = substitute_callout;
542
0
  mcontext->substitute_callout_data = substitute_callout_data;
543
0
  return 0;
544
0
}
545
546
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
547
pcre2_set_substitute_case_callout(
548
    pcre2_match_context *mcontext,
549
    PCRE2_SIZE (*substitute_case_callout)(PCRE2_SPTR input, PCRE2_SIZE input_length,
550
                                          PCRE2_UCHAR *output, PCRE2_SIZE output_capacity,
551
                                          int case_operation, void *substitute_case_callout_data),
552
    void *substitute_case_callout_data)
553
0
{
554
0
  PCRE2_ASSERT(mcontext != NULL);
555
0
  mcontext->substitute_case_callout = substitute_case_callout;
556
0
  mcontext->substitute_case_callout_data = substitute_case_callout_data;
557
0
  return 0;
558
0
}
559
560
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
561
pcre2_set_heap_limit(pcre2_match_context *mcontext, uint32_t limit)
562
0
{
563
0
  PCRE2_ASSERT(mcontext != NULL);
564
0
  mcontext->heap_limit = limit;
565
0
  return 0;
566
0
}
567
568
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
569
pcre2_set_match_limit(pcre2_match_context *mcontext, uint32_t limit)
570
29.8k
{
571
29.8k
  PCRE2_ASSERT(mcontext != NULL);
572
29.8k
  mcontext->match_limit = limit;
573
29.8k
  return 0;
574
29.8k
}
575
576
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
577
pcre2_set_depth_limit(pcre2_match_context *mcontext, uint32_t limit)
578
29.8k
{
579
29.8k
  PCRE2_ASSERT(mcontext != NULL);
580
29.8k
  mcontext->depth_limit = limit;
581
29.8k
  return 0;
582
29.8k
}
583
584
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
585
pcre2_set_offset_limit(pcre2_match_context *mcontext, PCRE2_SIZE limit)
586
0
{
587
0
  PCRE2_ASSERT(mcontext != NULL);
588
0
  mcontext->offset_limit = limit;
589
0
  return 0;
590
0
}
591
592
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
593
pcre2_get_heap_limit(pcre2_match_context *mcontext, uint32_t *limit)
594
0
{
595
0
  PCRE2_ASSERT(mcontext != NULL);
596
0
  PCRE2_ASSERT(limit != NULL);
597
0
  *limit = mcontext->heap_limit;
598
0
  return 0;
599
0
}
600
601
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
602
pcre2_get_match_limit(pcre2_match_context *mcontext, uint32_t *limit)
603
0
{
604
0
  PCRE2_ASSERT(mcontext != NULL);
605
0
  PCRE2_ASSERT(limit != NULL);
606
0
  *limit = mcontext->match_limit;
607
0
  return 0;
608
0
}
609
610
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
611
pcre2_get_depth_limit(pcre2_match_context *mcontext, uint32_t *limit)
612
0
{
613
0
  PCRE2_ASSERT(mcontext != NULL);
614
0
  PCRE2_ASSERT(limit != NULL);
615
0
  *limit = mcontext->depth_limit;
616
0
  return 0;
617
0
}
618
619
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
620
pcre2_get_offset_limit(pcre2_match_context *mcontext, PCRE2_SIZE *limit)
621
0
{
622
0
  PCRE2_ASSERT(mcontext != NULL);
623
0
  PCRE2_ASSERT(limit != NULL);
624
0
  *limit = mcontext->offset_limit;
625
0
  return 0;
626
0
}
627
628
/* These functions became obsolete at release 10.30. The first is kept as a
629
synonym for backwards compatibility. The second now does nothing. */
630
631
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
632
pcre2_set_recursion_limit(pcre2_match_context *mcontext, uint32_t limit)
633
0
{
634
0
  return pcre2_set_depth_limit(mcontext, limit);
635
0
}
636
637
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
638
pcre2_set_recursion_memory_management(pcre2_match_context *mcontext,
639
                                      void *(*mymalloc)(size_t size, void *mydata),
640
                                      void (*myfree)(void *ptr, void *mydata), void *mydata)
641
0
{
642
0
  (void)mcontext;
643
0
  (void)mymalloc;
644
0
  (void)myfree;
645
0
  (void)mydata;
646
0
  return 0;
647
0
}
648
649
650
/* ------------ Convert context ------------ */
651
652
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
653
pcre2_set_glob_separator(pcre2_convert_context *ccontext, uint32_t separator_char)
654
0
{
655
0
  PCRE2_ASSERT(ccontext != NULL);
656
0
  if (separator_char != CHAR_SLASH && separator_char != CHAR_BACKSLASH &&
657
0
      separator_char != CHAR_DOT)
658
0
    return PCRE2_ERROR_BADDATA;
659
660
0
  ccontext->glob_separator = separator_char;
661
0
  return 0;
662
0
}
663
664
/* Glob syntax characters cannot also be escape characters. */
665
static const char globpunct[] = STR_QUOTATION_MARK STR_NUMBER_SIGN STR_DOLLAR_SIGN STR_PERCENT_SIGN
666
    STR_AMPERSAND STR_APOSTROPHE STR_LEFT_PARENTHESIS STR_RIGHT_PARENTHESIS STR_PLUS STR_COMMA
667
        STR_DOT STR_SLASH STR_SEMICOLON STR_LESS_THAN_SIGN STR_EQUALS_SIGN STR_GREATER_THAN_SIGN
668
            STR_COMMERCIAL_AT STR_BACKSLASH STR_UNDERSCORE STR_GRAVE_ACCENT STR_LEFT_CURLY_BRACKET
669
                STR_VERTICAL_LINE STR_RIGHT_CURLY_BRACKET STR_TILDE;
670
671
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
672
pcre2_set_glob_escape(pcre2_convert_context *ccontext, uint32_t escape_char)
673
0
{
674
0
  PCRE2_ASSERT(ccontext != NULL);
675
0
  if (escape_char > 255 || (escape_char != 0 && strchr(globpunct, escape_char) == NULL))
676
0
    return PCRE2_ERROR_BADDATA;
677
678
0
  ccontext->glob_escape = escape_char;
679
0
  return 0;
680
0
}
681
682
/* End of pcre2_context.c */