mirror of
https://github.com/ascii-boxes/boxes.git
synced 2024-12-12 18:01:14 +01:00
Fix length argument to pcre2_substitute()
This commit is contained in:
parent
b0d2dd835d
commit
2f8f463a46
@ -85,7 +85,7 @@ unicode.o: unicode.c unicode.h boxes.h tools.h config.h
|
||||
shape.o: shape.c shape.h boxes.h tools.h config.h
|
||||
generate.o: generate.c generate.h boxes.h shape.h tools.h unicode.h config.h
|
||||
remove.o: remove.c remove.h boxes.h shape.h tools.h unicode.h config.h
|
||||
regulex.o: regulex.c regulex.h tools.h unicode.h config.h
|
||||
regulex.o: regulex.c regulex.h boxes.h tools.h unicode.h config.h
|
||||
lex.yy.o: lex.yy.c parser.h tools.h shape.h lexer.h config.h
|
||||
parser.o: parser.c parser.h tools.h shape.h lexer.h config.h
|
||||
misc/getopt.o: misc/getopt.c
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "boxes.h"
|
||||
#include "tools.h"
|
||||
#include "unicode.h"
|
||||
#include "regulex.h"
|
||||
@ -66,13 +67,15 @@ uint32_t *regex_replace(pcre2_code *search, char *replace, uint32_t *input, cons
|
||||
{
|
||||
PCRE2_SPTR replacement = u32_strconv_from_arg(replace, config_encoding);
|
||||
if (replacement == NULL) {
|
||||
fprintf(stderr, "Failed to convert replacement string to UTF-32 - \"%s\"\n", replace);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t options = PCRE2_SUBSTITUTE_OVERFLOW_LENGTH | PCRE2_SUBSTITUTE_EXTENDED
|
||||
| (global ? PCRE2_SUBSTITUTE_GLOBAL : 0);
|
||||
PCRE2_SIZE outlen = input_len * 2; /* estimated length of output buffer in characters, fine if too small */
|
||||
|
||||
PCRE2_SIZE bufsize = (input_len == 0) ? 16 : outlen;
|
||||
PCRE2_SIZE bufsize = (input_len < 8) ? 16 : outlen;
|
||||
uint32_t *output = (uint32_t *) malloc(sizeof(uint32_t) * bufsize); /* output buffer */
|
||||
int pcre2_rc;
|
||||
|
||||
@ -84,7 +87,8 @@ uint32_t *regex_replace(pcre2_code *search, char *replace, uint32_t *input, cons
|
||||
}
|
||||
PCRE2_SIZE outlen = bufsize;
|
||||
|
||||
pcre2_rc = pcre2_substitute(search, (PCRE2_SPTR) input, input_len,
|
||||
pcre2_rc = pcre2_substitute(search,
|
||||
(PCRE2_SPTR) input, PCRE2_ZERO_TERMINATED,
|
||||
0, /* start offset */
|
||||
options,
|
||||
NULL, /* ptr to a match data block */
|
||||
|
Loading…
Reference in New Issue
Block a user