Skip to content

Commit

Permalink
make sure to use either size_t or PCRE2_SIZE correctly (#195)
Browse files Browse the repository at this point in the history
It doesn't change much in practice, but helps clarify the interfaces
of some functions that were either documented with the wrong type or
had mismatching types between declaration and implementation.
  • Loading branch information
carenas authored Jan 23, 2023
1 parent 2f86495 commit 303e3bc
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion doc/html/pcre2_general_context_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h1>pcre2_general_context_create man page</h1>
</P>
<P>
<b>pcre2_general_context *pcre2_general_context_create(</b>
<b> void *(*<i>private_malloc</i>)(PCRE2_SIZE, void *),</b>
<b> void *(*<i>private_malloc</i>)(size_t, void *),</b>
<b> void (*<i>private_free</i>)(void *, void *), void *<i>memory_data</i>);</b>
</P>
<br><b>
Expand Down
4 changes: 2 additions & 2 deletions doc/html/pcre2_jit_stack_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ <h1>pcre2_jit_stack_create man page</h1>
<b>#include &#60;pcre2.h&#62;</b>
</P>
<P>
<b>pcre2_jit_stack *pcre2_jit_stack_create(PCRE2_SIZE <i>startsize</i>,</b>
<b> PCRE2_SIZE <i>maxsize</i>, pcre2_general_context *<i>gcontext</i>);</b>
<b>pcre2_jit_stack *pcre2_jit_stack_create(size_t <i>startsize</i>,</b>
<b> size_t <i>maxsize</i>, pcre2_general_context *<i>gcontext</i>);</b>
</P>
<br><b>
DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion doc/html/pcre2_set_recursion_memory_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1>pcre2_set_recursion_memory_management man page</h1>
<P>
<b>int pcre2_set_recursion_memory_management(</b>
<b> pcre2_match_context *<i>mcontext</i>,</b>
<b> void *(*<i>private_malloc</i>)(PCRE2_SIZE, void *),</b>
<b> void *(*<i>private_malloc</i>)(size_t, void *),</b>
<b> void (*<i>private_free</i>)(void *, void *), void *<i>memory_data</i>);</b>
</P>
<br><b>
Expand Down
10 changes: 5 additions & 5 deletions doc/html/pcre2api.html
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ <h1>pcre2api man page</h1>
<b>void pcre2_jit_free_unused_memory(pcre2_general_context *<i>gcontext</i>);</b>
<br>
<br>
<b>pcre2_jit_stack *pcre2_jit_stack_create(PCRE2_SIZE <i>startsize</i>,</b>
<b> PCRE2_SIZE <i>maxsize</i>, pcre2_general_context *<i>gcontext</i>);</b>
<b>pcre2_jit_stack *pcre2_jit_stack_create(size_t <i>startsize</i>,</b>
<b> size_t <i>maxsize</i>, pcre2_general_context *<i>gcontext</i>);</b>
<br>
<br>
<b>void pcre2_jit_stack_assign(pcre2_match_context *<i>mcontext</i>,</b>
Expand Down Expand Up @@ -343,7 +343,7 @@ <h1>pcre2api man page</h1>
<br>
<b>int pcre2_set_recursion_memory_management(</b>
<b> pcre2_match_context *<i>mcontext</i>,</b>
<b> void *(*<i>private_malloc</i>)(PCRE2_SIZE, void *),</b>
<b> void *(*<i>private_malloc</i>)(size_t, void *),</b>
<b> void (*<i>private_free</i>)(void *, void *), void *<i>memory_data</i>);</b>
<br>
<br>
Expand Down Expand Up @@ -2035,8 +2035,8 @@ <h1>pcre2api man page</h1>
<b>void pcre2_jit_free_unused_memory(pcre2_general_context *<i>gcontext</i>);</b>
<br>
<br>
<b>pcre2_jit_stack *pcre2_jit_stack_create(PCRE2_SIZE <i>startsize</i>,</b>
<b> PCRE2_SIZE <i>maxsize</i>, pcre2_general_context *<i>gcontext</i>);</b>
<b>pcre2_jit_stack *pcre2_jit_stack_create(size_t <i>startsize</i>,</b>
<b> size_t <i>maxsize</i>, pcre2_general_context *<i>gcontext</i>);</b>
<br>
<br>
<b>void pcre2_jit_stack_assign(pcre2_match_context *<i>mcontext</i>,</b>
Expand Down
2 changes: 1 addition & 1 deletion doc/pcre2_general_context_create.3
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PCRE2 - Perl-compatible regular expressions (revised API)
.PP
.nf
.B pcre2_general_context *pcre2_general_context_create(
.B " void *(*\fIprivate_malloc\fP)(PCRE2_SIZE, void *),"
.B " void *(*\fIprivate_malloc\fP)(size_t, void *),"
.B " void (*\fIprivate_free\fP)(void *, void *), void *\fImemory_data\fP);"
.fi
.
Expand Down
4 changes: 2 additions & 2 deletions doc/pcre2_jit_stack_create.3
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ PCRE2 - Perl-compatible regular expressions (revised API)
.B #include <pcre2.h>
.PP
.nf
.B pcre2_jit_stack *pcre2_jit_stack_create(PCRE2_SIZE \fIstartsize\fP,
.B " PCRE2_SIZE \fImaxsize\fP, pcre2_general_context *\fIgcontext\fP);"
.B pcre2_jit_stack *pcre2_jit_stack_create(size_t \fIstartsize\fP,
.B " size_t \fImaxsize\fP, pcre2_general_context *\fIgcontext\fP);"
.fi
.
.SH DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion doc/pcre2_set_recursion_memory_management.3
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ PCRE2 - Perl-compatible regular expressions (revised API)
.nf
.B int pcre2_set_recursion_memory_management(
.B " pcre2_match_context *\fImcontext\fP,"
.B " void *(*\fIprivate_malloc\fP)(PCRE2_SIZE, void *),"
.B " void *(*\fIprivate_malloc\fP)(size_t, void *),"
.B " void (*\fIprivate_free\fP)(void *, void *), void *\fImemory_data\fP);"
.fi
.
Expand Down
10 changes: 5 additions & 5 deletions doc/pcre2api.3
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ document for an overview of all the PCRE2 documentation.
.sp
.B void pcre2_jit_free_unused_memory(pcre2_general_context *\fIgcontext\fP);
.sp
.B pcre2_jit_stack *pcre2_jit_stack_create(PCRE2_SIZE \fIstartsize\fP,
.B " PCRE2_SIZE \fImaxsize\fP, pcre2_general_context *\fIgcontext\fP);"
.B pcre2_jit_stack *pcre2_jit_stack_create(size_t \fIstartsize\fP,
.B " size_t \fImaxsize\fP, pcre2_general_context *\fIgcontext\fP);"
.sp
.B void pcre2_jit_stack_assign(pcre2_match_context *\fImcontext\fP,
.B " pcre2_jit_callback \fIcallback_function\fP, void *\fIcallback_data\fP);"
Expand Down Expand Up @@ -275,7 +275,7 @@ document for an overview of all the PCRE2 documentation.
.sp
.B int pcre2_set_recursion_memory_management(
.B " pcre2_match_context *\fImcontext\fP,"
.B " void *(*\fIprivate_malloc\fP)(PCRE2_SIZE, void *),"
.B " void *(*\fIprivate_malloc\fP)(size_t, void *),"
.B " void (*\fIprivate_free\fP)(void *, void *), void *\fImemory_data\fP);"
.fi
.sp
Expand Down Expand Up @@ -1995,8 +1995,8 @@ also set.
.sp
.B void pcre2_jit_free_unused_memory(pcre2_general_context *\fIgcontext\fP);
.sp
.B pcre2_jit_stack *pcre2_jit_stack_create(PCRE2_SIZE \fIstartsize\fP,
.B " PCRE2_SIZE \fImaxsize\fP, pcre2_general_context *\fIgcontext\fP);"
.B pcre2_jit_stack *pcre2_jit_stack_create(size_t \fIstartsize\fP,
.B " size_t \fImaxsize\fP, pcre2_general_context *\fIgcontext\fP);"
.sp
.B void pcre2_jit_stack_assign(pcre2_match_context *\fImcontext\fP,
.B " pcre2_jit_callback \fIcallback_function\fP, void *\fIcallback_data\fP);"
Expand Down
6 changes: 3 additions & 3 deletions src/pcre2.h.generic
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION pcre2_config(uint32_t, void *);
PCRE2_EXP_DECL pcre2_general_context *PCRE2_CALL_CONVENTION \
pcre2_general_context_copy(pcre2_general_context *); \
PCRE2_EXP_DECL pcre2_general_context *PCRE2_CALL_CONVENTION \
pcre2_general_context_create(void *(*)(PCRE2_SIZE, void *), \
pcre2_general_context_create(void *(*)(size_t, void *), \
void (*)(void *, void *), void *); \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
pcre2_general_context_free(pcre2_general_context *);
Expand Down Expand Up @@ -628,7 +628,7 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_recursion_limit(pcre2_match_context *, uint32_t); \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_recursion_memory_management(pcre2_match_context *, \
void *(*)(PCRE2_SIZE, void *), void (*)(void *, void *), void *);
void *(*)(size_t, void *), void (*)(void *, void *), void *);

#define PCRE2_CONVERT_CONTEXT_FUNCTIONS \
PCRE2_EXP_DECL pcre2_convert_context *PCRE2_CALL_CONVENTION \
Expand Down Expand Up @@ -771,7 +771,7 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
pcre2_jit_free_unused_memory(pcre2_general_context *); \
PCRE2_EXP_DECL pcre2_jit_stack *PCRE2_CALL_CONVENTION \
pcre2_jit_stack_create(PCRE2_SIZE, PCRE2_SIZE, pcre2_general_context *); \
pcre2_jit_stack_create(size_t, size_t, pcre2_general_context *); \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
pcre2_jit_stack_assign(pcre2_match_context *, pcre2_jit_callback, void *); \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
Expand Down
6 changes: 3 additions & 3 deletions src/pcre2.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION pcre2_config(uint32_t, void *);
PCRE2_EXP_DECL pcre2_general_context *PCRE2_CALL_CONVENTION \
pcre2_general_context_copy(pcre2_general_context *); \
PCRE2_EXP_DECL pcre2_general_context *PCRE2_CALL_CONVENTION \
pcre2_general_context_create(void *(*)(PCRE2_SIZE, void *), \
pcre2_general_context_create(void *(*)(size_t, void *), \
void (*)(void *, void *), void *); \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
pcre2_general_context_free(pcre2_general_context *);
Expand Down Expand Up @@ -628,7 +628,7 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_recursion_limit(pcre2_match_context *, uint32_t); \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_recursion_memory_management(pcre2_match_context *, \
void *(*)(PCRE2_SIZE, void *), void (*)(void *, void *), void *);
void *(*)(size_t, void *), void (*)(void *, void *), void *);

#define PCRE2_CONVERT_CONTEXT_FUNCTIONS \
PCRE2_EXP_DECL pcre2_convert_context *PCRE2_CALL_CONVENTION \
Expand Down Expand Up @@ -773,7 +773,7 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
pcre2_jit_free_unused_memory(pcre2_general_context *); \
PCRE2_EXP_DECL pcre2_jit_stack *PCRE2_CALL_CONVENTION \
pcre2_jit_stack_create(PCRE2_SIZE, PCRE2_SIZE, pcre2_general_context *); \
pcre2_jit_stack_create(size_t, size_t, pcre2_general_context *); \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
pcre2_jit_stack_assign(pcre2_match_context *, pcre2_jit_callback, void *); \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
Expand Down
2 changes: 1 addition & 1 deletion src/pcre2_intmodedep.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ argument in 8-bit and 16-bit modes, so we need no more than a 16-bit field
here.) */

#undef CODE_BLOCKSIZE_TYPE
#define CODE_BLOCKSIZE_TYPE size_t
#define CODE_BLOCKSIZE_TYPE PCRE2_SIZE

#undef LOOKBEHIND_MAX
#define LOOKBEHIND_MAX UINT16_MAX
Expand Down
8 changes: 4 additions & 4 deletions src/pcre2test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,7 @@ return sys_errlist[n];

/* Alternative memory functions, to test functionality. */

static void *my_malloc(PCRE2_SIZE size, void *data)
static void *my_malloc(size_t size, void *data)
{
void *block = malloc(size);
(void)data;
Expand Down Expand Up @@ -4331,7 +4331,7 @@ static void
show_memory_info(void)
{
uint32_t name_count, name_entry_size;
size_t size, cblock_size;
PCRE2_SIZE size, cblock_size;

/* One of the test_mode values will always be true, but to stop a compiler
warning we must initialize cblock_size. */
Expand All @@ -4355,7 +4355,7 @@ if (test_mode == PCRE32_MODE) cblock_size = sizeof(pcre2_real_code_32);
grumbling about potential overflow. */

fprintf(outfile, "Memory allocation (code space): %" SIZ_FORM "\n", size -
(size_t)name_count * (size_t)name_entry_size * (size_t)code_unit_size -
(PCRE2_SIZE)name_count * (PCRE2_SIZE)name_entry_size * (PCRE2_SIZE)code_unit_size -
cblock_size);

if (pat_patctl.jit != 0)
Expand All @@ -4374,7 +4374,7 @@ if (pat_patctl.jit != 0)
static void
show_framesize(void)
{
size_t frame_size;
PCRE2_SIZE frame_size;
(void)pattern_info(PCRE2_INFO_FRAMESIZE, &frame_size, FALSE);
fprintf(outfile, "Frame size for pcre2_match(): %" SIZ_FORM "\n", frame_size);
}
Expand Down

0 comments on commit 303e3bc

Please sign in to comment.