diff --git a/doc/pcre2api.3 b/doc/pcre2api.3 index 1100e59af..48cf53888 100644 --- a/doc/pcre2api.3 +++ b/doc/pcre2api.3 @@ -1,4 +1,4 @@ -.TH PCRE2API 3 "19 October 2025" "PCRE2 10.48-DEV" +.TH PCRE2API 3 "29 October 2025" "PCRE2 10.48-DEV" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .sp @@ -1296,14 +1296,15 @@ documentation for more details. .sp PCRE2_CONFIG_JITTARGET .sp -The \fIwhere\fP argument should point to a buffer that is at least 64 code -units long. (The exact length required can be found by calling -\fBpcre2_config()\fP with \fBwhere\fP set to NULL.) The buffer is filled with a -string that contains the name of the architecture for which the JIT compiler is -configured, for example "x86 32bit (little endian + unaligned)". If JIT support -is not available, PCRE2_ERROR_BADOPTION is returned, otherwise the number of -code units used is returned. This is the length of the string, plus one unit -for the terminating zero. +The \fIwhere\fP argument should point to a buffer that is suitably aligned and +wide enough to hold the full string. The exact length required is returned when +calling \fBpcre2_config()\fP with \fBwhere\fP set to NULL first. The buffer is +filled with a string that contains the name of the architecture for which the JIT +compiler is configured at build time, for example, a 64-bit ARM CPU that supports +the Armv8.1 extension writes "ARM-64 (LSE) 64bit (little endian + unaligned)". +If JIT support is not available, PCRE2_ERROR_BADOPTION is returned, otherwise +the number of code units used is returned. This is the length of the string, +plus one code unit for the NUL character. .sp PCRE2_CONFIG_LINKSIZE .sp @@ -4606,6 +4607,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 19 October 2025 +Last updated: 29 October 2025 Copyright (c) 1997-2024 University of Cambridge. .fi diff --git a/src/pcre2test.c b/src/pcre2test.c index 3242b5ce7..81e93741e 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -2942,9 +2942,9 @@ static int pcre2_config(uint32_t what, void *where) DISPATCH(return, pcre2_config_, (what, where)); } -static void config_str(uint32_t what, char *where) +static char *config_str(uint32_t what, char *where, int size) { -DISPATCH(, config_str_, (what, where)); +DISPATCH(return, config_str_, (what, where, size)); } static BOOL decode_modifiers(uint8_t *p, int ctx, patctl *pctl, datctl *dctl) @@ -3014,7 +3014,7 @@ static void print_version(FILE *f, BOOL include_mode) { char buf[VERSION_SIZE]; -config_str(PCRE2_CONFIG_VERSION, buf); +config_str(PCRE2_CONFIG_VERSION, buf, sizeof(buf)); fprintf(f, "PCRE2 version %s", buf); if (include_mode) { @@ -3033,7 +3033,7 @@ static void print_unicode_version(FILE *f) { char buf[VERSION_SIZE]; -config_str(PCRE2_CONFIG_UNICODE_VERSION, buf); +config_str(PCRE2_CONFIG_UNICODE_VERSION, buf, sizeof(buf)); fprintf(f, "Unicode version %s", buf); } @@ -3046,9 +3046,9 @@ fprintf(f, "Unicode version %s", buf); static void print_jit_target(FILE *f) { -char buf[VERSION_SIZE]; -config_str(PCRE2_CONFIG_JITTARGET, buf); +char *buf = config_str(PCRE2_CONFIG_JITTARGET, NULL, 0); fputs(buf, f); +free(buf); } diff --git a/src/pcre2test_inc.h b/src/pcre2test_inc.h index c47074171..ce808a82f 100644 --- a/src/pcre2test_inc.h +++ b/src/pcre2test_inc.h @@ -558,24 +558,41 @@ return 0; Arguments: what the item to read - where the 8-bit buffer to receive the string + where the 8-bit buffer to receive the string (NULLABLE) + size sizeof(where) or 0 to ask for the buffer to be allocated + +Returns: the string where the data was written */ -static void -config_str(uint32_t what, char *where) +static char * +config_str(uint32_t what, char *where, int size) { -int r1, r2; -PCRE2_UCHAR buf[VERSION_SIZE]; +int r2; +PCRE2_UCHAR *buf; +int needed_len; -r1 = pcre2_config(what, NULL); -r2 = pcre2_config(what, buf); -if (r1 < 0 || r1 != r2 || r1 >= VERSION_SIZE) +needed_len = pcre2_config(what, NULL); +if (needed_len <= 0) { cfprintf(clr_test_error, stderr, "pcre2test: Error in pcre2_config(%d)\n", what); exit(1); } +else if (size != 0 && needed_len > size) + { + cfprintf(clr_test_error, stderr, + "pcre2test: Static buffer provided to pcre2_config(%d) too small\n", what); + exit(1); + } + +buf = malloc(needed_len * sizeof(PCRE2_UCHAR)); +r2 = pcre2_config(what, buf); +PCRE2_ASSERT(r2 == needed_len); + +if (where == NULL) where = malloc(needed_len); +while (r2-- > 0) where[r2] = (char)buf[r2]; +free(buf); -while (r1-- > 0) where[r1] = (char)buf[r1]; +return where; }