Skip to content

Commit

Permalink
Add some casts and other tidies to pcre2test formatting of size_t values
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipHazel committed Apr 23, 2022
1 parent b52d055 commit ff5402a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Alpine Linux).

2. Merged patch from @carenas (GitHub #110) for pthreads support in CMake.

3. SSF scorecards grumbled about possible overflow in an expression in
pcre2test. It never would have overflowed in practice, but some casts have been
added and at the some time there's been some tidying of fprints that output
size_t values.


Version 10.40 15-April-2022
---------------------------
Expand Down
16 changes: 11 additions & 5 deletions src/pcre2test.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,6 @@ static BOOL jit_was_used;
static BOOL restrict_for_perl_test = FALSE;
static BOOL show_memory = FALSE;

static int code_unit_size; /* Bytes */
static int jitrc; /* Return from JIT compile */
static int test_mode = DEFAULT_TEST_MODE;
static int timeit = 0;
Expand All @@ -937,6 +936,7 @@ clock_t total_compile_time = 0;
clock_t total_jit_compile_time = 0;
clock_t total_match_time = 0;

static uint32_t code_unit_size; /* Bytes */
static uint32_t dfa_matched;
static uint32_t forbid_utf = 0;
static uint32_t maxlookbehind;
Expand Down Expand Up @@ -4307,12 +4307,18 @@ if (test_mode == PCRE32_MODE) cblock_size = sizeof(pcre2_real_code_32);
(void)pattern_info(PCRE2_INFO_SIZE, &size, FALSE);
(void)pattern_info(PCRE2_INFO_NAMECOUNT, &name_count, FALSE);
(void)pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &name_entry_size, FALSE);
fprintf(outfile, "Memory allocation (code space): %d\n",
(int)(size - name_count*name_entry_size*code_unit_size - cblock_size));

/* The uint32_t variables are cast before multiplying to stop code analyzers
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 -
cblock_size);

if (pat_patctl.jit != 0)
{
(void)pattern_info(PCRE2_INFO_JITSIZE, &size, FALSE);
fprintf(outfile, "Memory allocation (JIT code): %d\n", (int)size);
fprintf(outfile, "Memory allocation (JIT code): %" SIZ_FORM "\n", size);
}
}

Expand All @@ -4327,7 +4333,7 @@ show_framesize(void)
{
size_t frame_size;
(void)pattern_info(PCRE2_INFO_FRAMESIZE, &frame_size, FALSE);
fprintf(outfile, "Frame size for pcre2_match(): %d\n", (int)frame_size);
fprintf(outfile, "Frame size for pcre2_match(): %" SIZ_FORM "\n", frame_size);
}


Expand Down

0 comments on commit ff5402a

Please sign in to comment.